FSD Lab
FSD Lab
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script>
function validateEmail() {
// Use the test() method to check if the input matches the pattern
if (regex.test(emailInput)) {
} else {
document.getElementById("result").style.color = "red";
</script>
</head>
<body>
<button onclick="validateEmail()">Validate</button>
<p id="result"></p>
</body>
</html>
7h)Write a program to explain user-defined object by using properties, methods,
accessors,constructors and display.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<div>
<p id="carDetails"></p>
</div>
<script>
this.displayCarDetails = function() {
};
this.getYear = function() {
return this.year;
};
this.setYear = function(newYear) {
this.year = newYear;
};
function createCar() {
document.getElementById('carDetails').innerHTML = `
`;
</script>
</body>
</html>
8 a)write a program which asks the user to enter three integers, obtains the numbers from the
user and outputs HTML text that displays the larger number following by the words "LARGER
NUMBER" Iin an information message dialog. If the numbers are equal ,output HTML text as
"EQUAL NUMBERS".
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Number Comparison</title>
<script type="text/javascript">
function compareNumbers() {
alert("EQUAL NUMBERS");
} else {
</script>
</head>
<body>
<h2>Enter Three Numbers</h2>
</body>
</html>
Compare Numbers
Equal numbers
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script>
function displayWeekday() {
let day;
switch(dayNumber) {
case 1:
day = "Sunday";
break;
case 2:
day = "Monday";
break;
case 3:
day = "Tuesday";
break;
case 4:
day = "Wednesday";
break;
case 5:
day = "Thursday";
break;
case 6:
day = "Friday";
break;
case 7:
day = "Saturday";
break;
default:
</script>
</head>
<body>
<p id="result"></p>
</body>
</html>
Output:-
Show Weekday
8c)Write a program to print 1 to 10 numbers using for, while and do-while loops.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script>
function printNumbers() {
let j = 1;
j++;
let k = 1;
do {
k++;
</script>
</head>
<body onload="printNumbers()">
<p id="forLoop"></p>
<p id="whileLoop"></p>
<p id="doWhileLoop"></p>
</body>
</html>
Output:-
For Loop: 1 2 3 4 5 6 7 8 9 10
While Loop: 1 2 3 4 5 6 7 8 9 10
Do-While Loop: 1 2 3 4 5 6 7 8 9 10
8d)write a program to print data in object using for-in,for-each and for-of loops.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<h2>Using for-in Loop</h2>
<ul id="for-in-loop"></ul>
<ul id="for-each-loop"></ul>
<ul id="for-of-loop"></ul>
<script>
// Sample object
const user = {
name: "John",
age: 30,
job: "Developer"
};
let li = document.createElement("li");
forInLoop.appendChild(li);
}
// Using forEach method (requires array conversion)
let li = document.createElement("li");
forEachLoop.appendChild(li);
});
// Using for-of loop with Object entries (Array of [key, value] pairs)
let li = document.createElement("li");
forOfLoop.appendChild(li);
</script>
</body>
</html>
Output:-
name: John
age: 30
job: Developer
name: John
age: 30
job: Developer
name: John
age: 30
job: Developer
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<button onclick="checkArmstrong()">Check</button>
<p id="result"></p>
<script>
function checkArmstrong() {
let sum = 0;
document.getElementById("result").textContent = resultMessage;
</script>
</body>
</html>
Output:-
5 is an Armstrong number!
8f)write a program to display the denomination of the amount deposited in the bank in
terms of 100’s,50’s,20’s,10’s,5’s,2’s&1’s.(eg: if deposited amount is rs.163, the putput should
be 1-100’s,1-50’s,1-10’s,1-2’s &1-1’s)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Denomination Calculator</title>
<script>
function calculateDenominations() {
return;
if (count > 0) {
document.getElementById("result").innerHTML = results;
</script>
</head>
<body>
<h2>Denomination Calculator</h2>
<button onclick="calculateDenominations()">Calculate</button>
<h3>Denominations:</h3>
<div id="result"></div>
</body>
</html>
Output:-
Denomination Calculator
Denominations:
1 - 100's
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Number Operations</title>
<script>
function factorial(num) {
let fact = 1;
fact *= i;
}
return fact;
function fibonacci(num) {
function isPrime(num) {
return true;
function primeNumbers(num) {
if (isPrime(i)) primes.push(i);
}
function isPalindrome(num) {
function displayResults() {
number.";
return;
document.getElementById("results").innerHTML = `
<p>Factorial: ${factorial(num)}</p>
`;
</script>
</head>
<body>
<h2>Number Operations</h2>
<p>Enter a number to perform operations:</p>
<button onclick="displayResults()">Calculate</button>
<div id="results"></div>
</body>
</html>
Calculate
9c) Write a program to validate the following fields in a registration page i. Name ii. Mobile iii. E-
mail
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script>
function validateForm() {
if (!mobilePattern.test(mobile)) {
if (!emailPattern.test(email)) {
if (errors.length > 0) {
document.getElementById("errorMessages").innerHTML = errors.join("<br>");
return false;
} else {
alert("Registration Successful!");
return true;
</script>
</head>
<body>
<h2>Registration Form</h2>
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>
<label for="mobile">Mobile:</label>
<label for="email">Email:</label>
<button type="submit">Register</button>
</form>
</body>
</html>
output:-Registration Form
Name:
Mobile:
Email:
Register