Js Code
Js Code
Js Code
function calculateCircleArea(radius) {
// Calculate areas
<html lang="en">
<head>
<title>Timer in JS</title>
</head>
<body>
<h2><b>Countdown Timer</b></h2>
<h3 id="result"></h3>
<script type="text/javascript">
function startTimer() {
let x = setInterval(function () {
if (distance < 0) {
}, 1000);
</script>
</body>
</html>
EXP 6: (Array data operation)
<!DOCTYPE html>
<html lang="en">
<head>
<title>Array Operations</title>
</head>
<body>
<h1>Array Operations</h1>
<br>
<br>
<br>
<br>
<br>
<br><br>
<br>
<br>
<br><br>
<button type="button" onclick="checkArrayElement()">Check</button>
<br>
<h2>Empty Array</h2>
<br>
<script>
function arrayDisplay() {
function removeArrayElement() {
function checkArrayElement() {
function emptyArray() {
</script>
</body>
</html>
Exp7: (Object and array)
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<script>
arr.push(obj);
// document.write(arr);
function checkObject(arr) {
if (result) {
document.write(`[${arr}] is an array.`);
} else {
// Original array
// Object to add
checkObject(array);
// Call the function to insert the object into the array
insertObject(array, object);
</script>
</body>
</html>
EXP 8: (Set Operations)
<!DOCTYPE html>
<html lang="en">
<head>
<title>Set Operations</title>
</head>
<body>
<h1>Set Operations</h1>
<div id="output">
</div>
<script>
// Output element
function displayResults() {
"<br>";
displayResults();
</script>
</body>
</html>
EXP9:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<br>
<br>
<br>
<script>
button.addEventListener("mouseover", function() {
document.body.style.backgroundColor = getRandomColor();
});
// Function to change the background color on focus for the anchor tag
link.addEventListener("focus", function() {
document.body.style.backgroundColor = getRandomColor();
});
function getRandomColor() {
return color;
</script>
</body>
</html>
EXP 9: (Handle different events)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Website Home Page</title>
</head>
<body>
<h1>Welcome to Our Website</h1>
<br>
<button id="changeColorButton">Change Background Color
(Mouseover)</button>
<br>
<br>
<a href="#" id="changeColorLink">Change Background Color
(Focus)</a>
<script>
const button = document.getElementById("changeColorButton");
const link = document.getElementById("changeColorLink");
// Function to change the background color on mouseover
button.addEventListener("mouseover", function() {
document.body.style.backgroundColor = getRandomColor();
});
// Function to change the background color on focus for the anchor
tag
link.addEventListener("focus", function() {
document.body.style.backgroundColor = getRandomColor();
});
// Helper function to generate a random color
function getRandomColor() {
const letters = "0123456789ABCDEF";
let color = "#";
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
</script>
</body>
</html>
EXP10: (form)
1.Index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
method="post">
<label for="name">Name:</label>
<label for="address">Address:</label>
<label for="city">City:</label>
<label for="state">State:</label>
<label for="gender">Gender:</label>
<option value="male">Male</option>
<option value="female">Female</option>
</select><br>
</form>
<script src="main.js"></script>
</body>
</html>
2. submission_success.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Submission Successful</title>
</head>
<body>
</body>
</html>
3. main.js
function validateForm() {
if (!/^[A-Za-z\s]+$/.test(name)) {
errorMessages.innerHTML += "Invalid name. Please enter a valid name.<br>";
return false;
if (!/^\d{10}$/.test(mobile)) {
return false;
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
return false;
return true;
}
EXP 10 : Display form on web
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<label for="address">Address:</label>
<label for="city">City:</label>
<label for="state">State:</label>
<label for="gender">Gender:</label>
<label for="male">Male</label>
<label for="female">Female</label><br><br>
<button type="submit">Submit</button>
</form>
<h2>Student Information</h2>
<p id="displayInfo"></p>
<script>
function validateForm() {
// Regex for valid name (allows alphabets, space, hyphen, and apostrophe)
if (!namePattern.test(fullName)) {
return false;
if (!mobilePattern.test(mobile)) {
alert("Please enter a valid 10-digit mobile number.");
return false;
displayInfo.innerHTML = `
<strong>Address:</strong> ${address}<br>
<strong>City:</strong> ${city}<br>
<strong>State:</strong> ${state}<br>
<strong>Gender:</strong> ${gender.value}<br>
<strong>Email:</strong> ${email}
`;
return false;
</script>
</body>
</html>