JavaScript Practice Programs
1. Variables and Data Types
<!DOCTYPE html>
<html>
<head>
<title>Variables and Data Types</title>
</head>
<body>
<h2>Variables and Data Types</h2>
<script>
var name = "John";
let age = 25;
const isStudent = true;
document.write("<p>Name: " + name + "</p>");
document.write("<p>Age: " + age + "</p>");
document.write("<p>Is Student: " + isStudent + "</p>");
</script>
</body>
</html>
2. Arithmetic Operators
<!DOCTYPE html>
<html>
<head>
<title>Arithmetic Operators</title>
</head>
<body>
<h2>Arithmetic Operators</h2>
<script>
let a = 10, b = 5;
document.write("<p>Addition: " + (a + b) + "</p>");
document.write("<p>Subtraction: " + (a - b) + "</p>");
document.write("<p>Multiplication: " + (a * b) + "</p>");
document.write("<p>Division: " + (a / b) + "</p>");
document.write("<p>Modulus: " + (a % b) + "</p>");
</script>
</body>
</html>
3. Comparison Operators
<!DOCTYPE html>
<html>
<head>
<title>Comparison Operators</title>
</head>
<body>
<h2>Comparison Operators</h2>
<script>
let x = 5, y = 10;
document.write("<p>Equal to: " + (x == y) + "</p>");
document.write("<p>Not Equal to: " + (x != y) + "</p>");
document.write("<p>Greater than: " + (x > y) + "</p>");
document.write("<p>Less than: " + (x < y) + "</p>");
</script>
</body>
</html>
4. Looping Statements (For Loop)
<!DOCTYPE html>
<html>
<head>
<title>For Loop</title>
</head>
<body>
<h2>For Loop: Numbers from 1 to 5</h2>
<script>
for (let i = 1; i <= 5; i++) {
document.write("<p>" + i + "</p>");
}
</script>
</body>
</html>
5. Function Definition & Calling
<!DOCTYPE html>
<html>
<head>
<title>Functions in JavaScript</title>
</head>
<body>
<h2>Function to Add Two Numbers</h2>
<script>
function addNumbers(a, b) {
return a + b;
}
let result = addNumbers(5, 10);
document.write("<p>Sum: " + result + "</p>");
</script>
</body>
</html>
I have included five sample programs based on your request. If you need more, let me know, and I
will add them accordingly!