lOMoAR cPSD| 46020670
CSS Practical exam Answers 2025
1. Write a program to execute the conditional operator(ternary) in JavaScript.
Ans: <html>
<head>
<title>Even or Odd Checker</title>
</head>
<body>
<script>
// Ask the user to enter a number var number =
prompt("Enter a number:");
// Check if the number is even or odd using the ternary operator var result =
(number % 2 === 0) ? "Even" : "Odd";
// Display the result using an alert box
alert("The number " + number + " is " + result + "."); </script>
</body>
</html>
2. Write a JavaScript program to print the factorial of a given number.
Ans: <html>
<head>
<title>Factorial Calculator</title>
</head>
<body>
, lOMoAR cPSD| 46020670
<script>
// Ask the user to enter a number
var number = prompt("Enter a number to calculate its factorial:");
// Convert the input to a number number =
parseInt(number);
// Function to calculate factorial function
factorial(n) { if (n === 0 || n === 1) { return
1; // Base case: 0! and 1! are 1
}
return n * factorial(n - 1); // Recursive case }
// Calculate the factorial of the given number var result =
factorial(number);
// Display the result using document.write
document.write("The factorial of " + number + " is " + result + "."); </script>
</body>
</html>
3. Write a JavaScript program to print the Fibonacci series till 10 number.
Ans: simple one:
<html>
<head>
<title>Fibonacci Series</title>
</head>
<body>
, lOMoAR cPSD| 46020670
<script>
var n = 10; // Number of terms
var a = 0, b = 1, next; // Initialize the first two numbers
document.write("Fibonacci series up to 10 numbers: ");
for (var i = 1; i <= n; i++) {
document.write(a + " "); // Print the current number next = a
+ b; // Calculate the next number a = b; // Update 'a' to the next
number b = next; // Update 'b' to the next number
}
</script>
</body>
</html>
User input one:
<html>
<head>
<title>Fibonacci Series</title>
</head>
<body>
<script>
// Take user input for the number of terms
var n = prompt("Enter the number of terms for the Fibonacci series:"); n = parseInt(n);
// Convert input to a number
var a = 0, b = 1, next; // Initialize the first two numbers
, lOMoAR cPSD| 46020670
document.write("Fibonacci series up to " + n + " numbers: ");
for (var i = 1; i <= n; i++) {
document.write(a + " "); // Print the current number next = a
+ b; // Calculate the next number a = b; // Update 'a' to the next
number b = next; // Update 'b' to the next number
}
</script>
</body>
</html>
4. Write a code to find out whether the year is leap year or not.
Ans: simple one:
<html>
<head>
<title>Leap Year Checker</title>
</head>
<body>
<script>
// Prompt the user to enter a year
var year = prompt("Enter a year to check if it is a leap year:"); year =
parseInt(year); // Convert the input to an integer
// Check if the year is a leap year
if ((year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0)) { alert(year + " is a leap
year.");
} else {
alert(year + " is not a leap year.");
CSS Practical exam Answers 2025
1. Write a program to execute the conditional operator(ternary) in JavaScript.
Ans: <html>
<head>
<title>Even or Odd Checker</title>
</head>
<body>
<script>
// Ask the user to enter a number var number =
prompt("Enter a number:");
// Check if the number is even or odd using the ternary operator var result =
(number % 2 === 0) ? "Even" : "Odd";
// Display the result using an alert box
alert("The number " + number + " is " + result + "."); </script>
</body>
</html>
2. Write a JavaScript program to print the factorial of a given number.
Ans: <html>
<head>
<title>Factorial Calculator</title>
</head>
<body>
, lOMoAR cPSD| 46020670
<script>
// Ask the user to enter a number
var number = prompt("Enter a number to calculate its factorial:");
// Convert the input to a number number =
parseInt(number);
// Function to calculate factorial function
factorial(n) { if (n === 0 || n === 1) { return
1; // Base case: 0! and 1! are 1
}
return n * factorial(n - 1); // Recursive case }
// Calculate the factorial of the given number var result =
factorial(number);
// Display the result using document.write
document.write("The factorial of " + number + " is " + result + "."); </script>
</body>
</html>
3. Write a JavaScript program to print the Fibonacci series till 10 number.
Ans: simple one:
<html>
<head>
<title>Fibonacci Series</title>
</head>
<body>
, lOMoAR cPSD| 46020670
<script>
var n = 10; // Number of terms
var a = 0, b = 1, next; // Initialize the first two numbers
document.write("Fibonacci series up to 10 numbers: ");
for (var i = 1; i <= n; i++) {
document.write(a + " "); // Print the current number next = a
+ b; // Calculate the next number a = b; // Update 'a' to the next
number b = next; // Update 'b' to the next number
}
</script>
</body>
</html>
User input one:
<html>
<head>
<title>Fibonacci Series</title>
</head>
<body>
<script>
// Take user input for the number of terms
var n = prompt("Enter the number of terms for the Fibonacci series:"); n = parseInt(n);
// Convert input to a number
var a = 0, b = 1, next; // Initialize the first two numbers
, lOMoAR cPSD| 46020670
document.write("Fibonacci series up to " + n + " numbers: ");
for (var i = 1; i <= n; i++) {
document.write(a + " "); // Print the current number next = a
+ b; // Calculate the next number a = b; // Update 'a' to the next
number b = next; // Update 'b' to the next number
}
</script>
</body>
</html>
4. Write a code to find out whether the year is leap year or not.
Ans: simple one:
<html>
<head>
<title>Leap Year Checker</title>
</head>
<body>
<script>
// Prompt the user to enter a year
var year = prompt("Enter a year to check if it is a leap year:"); year =
parseInt(year); // Convert the input to an integer
// Check if the year is a leap year
if ((year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0)) { alert(year + " is a leap
year.");
} else {
alert(year + " is not a leap year.");