Bca Wt Assignment Javascript
Bca Wt Assignment Javascript
BCA EA
1029802024
BCA WT ASSIGNMENT-JAVASCRIPT
1. Write a Javascript program to check whether a number input through prompt box is Odd or Even.
<html>
<head>
<title>Odd or Even Checker</title>
<script>
function checkOddEven() {
let number = prompt("Please enter a number:");
number = Number(number);
if (!isNaN(number)) {
if (number % 2 === 0) {
alert(number + " is an Even number.");
} else {
alert(number + " is an Odd number.");
}
} else {
alert("Please enter a valid number.");
}
}
</script>
</head>
<body>
<h1>Odd or Even Checker</h1>
<button onclick="checkOddEven()">Check Number</button>
</body>
</html>
2. Write a Javascript program to find the sum of even numbers till 100.
<html>
<head>
<title>Sum of Even Numbers</title>
<script>
function sumEvenNumbers() {
let sum = 0;
for (let i = 0; i <= 100; i++) {
if (i % 2 === 0) {
sum += i;
}
}
alert("The sum of even numbers from 0 to 100 is: " + sum);
}
</script>
</head>
<body>
<h2>Sum of Even Numbers Till 100</h2>
<button onclick="sumEvenNumbers()">Calculate Sum</button>
</body>
</html>
3. Write a Javascript program to calculate the squares and cubes of the numbers from 1 to 5 with the following
output. Number can be entered through the user.
<html>
<head>
<title>Squares and Cubes</title>
<script>
function calculateSquaresAndCubes() {
let num = prompt("Enter a number from 1 to 5 to calculate squares and
cubes:");
if (num >= 1 && num <= 5) {
let square = num * num;
let cube = num * num * num;
alert(`For number ${num}: Square = ${square}, Cube = ${cube}`);
} else {
alert("Please enter a number between 1 and 5.");
}
}
</script>
</head>
<body>
<h2>Squares and Cubes Calculator</h2>
<button onclick="calculateSquaresAndCubes()">Calculate Squares and Cubes</button>
</body>
</html>

4. Write a user defined recursive function to find the factorial of a number. The input should be taken from the user.
<html>
<head>
<title>Factorial Calculator</title>
<script>
function factorial(n) {
if (n <= 1) return 1;
return n * factorial(n - 1);
}
function getFactorial() {
let num = prompt("Enter a number to find its factorial:");
alert(`The factorial of ${num} is: ${factorial(num)}`);
}
</script>
</head>
<body>
<h2>Factorial Calculator</h2>
<button onclick="getFactorial()">Find Factorial</button>
</body>
</html>
5. Write a user defined function to find the maximum of 3 numbers using conditional operator/ternary operator.
<html>
<head>
<title>Maximum of Three Numbers</title>
<script>
function maxOfThree() {
let num1 = prompt("Enter the first number:");
let num2 = prompt("Enter the second number:");
let num3 = prompt("Enter the third number:");
let max = (num1 > num2 && num1 > num3) ? num1 : (num2 > num3 ? num2 : num3);
alert(`The maximum number is: ${max}`);
}
</script>
</head>
<body>
<h2>Find Maximum of Three Numbers</h2>
<button onclick="maxOfThree()">Find Maximum</button>
</body>
</html>
6. Write a JavaScript program to concatenate two strings.
<html>
<head>
<title>String Concatenation</title>
<script>
function concatenateStrings() {
let string1 = prompt("Enter the first string:");
let string2 = prompt("Enter the second string:");
alert(`The concatenated result is: ${string1} ${string2}`);
}
</script>
</head>
<body>
<h2>String Concatenation</h2>
<button onclick="concatenateStrings()">Concatenate Strings</button>
</body>
</html>
7. Write a program to access JavaScript object elements and array elements.
<html>
<head>
<title>Access Object and Array Elements</title>
<script>
function accessObjectArray() {
let person = { name: "John", age: 30, city: "New York" };
let fruits = ["Apple", "Banana", "Cherry"];
alert(`Person: Name - ${person.name}, Age - ${person.age}, City - $
{person.city}`);
alert(`Fruits: ${fruits[0]}, ${fruits[1]}, ${fruits[2]}`);
}
</script>
</head>
<body>
<h2>Access Object and Array Elements</h2>
<button onclick="accessObjectArray()">Access Elements</button>
</body>
</html>
8. Write a JavaScript program to find the sum of two numbers. Number should be entered using prompt popup windows.
<html>
<head>
<title>Sum of Two Numbers</title>
<script>
function sumOfTwoNumbers() {
let num1 = prompt("Enter the first number:");
let num2 = prompt("Enter the second number:");
alert(`The sum of ${num1} and ${num2} is: ${parseInt(num1) +
parseInt(num2)}`);
}
</script>
</head>
<body>
<h2>Sum of Two Numbers</h2>
<button onclick="sumOfTwoNumbers()">Calculate Sum</button>
</body>
</html>
9. Write a JavaScript program to find the maximum of two numbers using user defined function. The input should
be taken from the user.
<html>
<head>
<title>Maximum of Two Numbers</title>
<script>
function maxOfTwo() {
let num1 = prompt("Enter the first number:");
let num2 = prompt("Enter the second number:");
let max = (num1 > num2) ? num1 : num2;
alert(`The maximum number is: ${max}`);
}
</script>
</head>
<body>
<h2>Find Maximum of Two Numbers</h2>
<button onclick="maxOfTwo()">Find Maximum</button>
</body>
</html>
10. Write a JavaScript program to find the maximum of three numbers using user defined function. The input
should be taken from the user.
<html>
<head>
<title>Maximum of Three Numbers</title>
<script>
function maxOfThreeNumbers() {
let num1 = prompt("Enter the first number:");
let num2 = prompt("Enter the second number:");
let num3 = prompt("Enter the third number:");
let max = (num1 > num2 && num1 > num3) ? num1 : (num2 > num3 ? num2 : num3);
alert(`The maximum number is: ${max}`);
}
</script>
</head>
<body>
<h2>Find Maximum of Three Numbers</h2>
<button onclick="maxOfThreeNumbers()">Find Maximum</button>
</body>
</html>
11. Write a program to Implement event handling using onclick, onmouseover and onmouseout events
<html>
<head>
<title>Event Handling</title>
<script>
function handleClick() {
alert("Button clicked!");
}
function handleMouseOver() {
alert("Mouse over the button!");
}
function handleMouseOut() {
alert("Mouse out of the button!");
}
</script>
</head>
<body>
<h2>Event Handling Example</h2>
<button onclick="handleClick()">Click Me (OnClick)</button>
<button onmouseover="handleMouseOver()">Hover Me (OnMouseOver)</button>
<button onmouseout="handleMouseOut()">Mouse Out (OnMouseOut)</button>
</body>
</html>
12. Write a Java script program to show the usage of all the date, math and string objects.
<html>
<head>
<title>Using Date, Math, and String Objects</title>
<script>
function showObjectsUsage() {
let today = new Date();
alert("Today's date is: " + today);
BCA WT ASSIGNMENT-JAVASCRIPT
1. Write a Javascript program to check whether a number input through prompt box is Odd or Even.
<html>
<head>
<title>Odd or Even Checker</title>
<script>
function checkOddEven() {
let number = prompt("Please enter a number:");
number = Number(number);
if (!isNaN(number)) {
if (number % 2 === 0) {
alert(number + " is an Even number.");
} else {
alert(number + " is an Odd number.");
}
} else {
alert("Please enter a valid number.");
}
}
</script>
</head>
<body>
<h1>Odd or Even Checker</h1>
<button onclick="checkOddEven()">Check Number</button>
</body>
</html>