0% found this document useful (0 votes)
8 views4 pages

Wit5 1

The document contains two HTML programs demonstrating JavaScript concepts. The first program illustrates loops (for, while, and do-while) by displaying even numbers, a countdown, and a greeting. The second program showcases functions by allowing users to call a message function, calculate the sum of two numbers, and find the square of a number.

Uploaded by

sheoranpooja726
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Wit5 1

The document contains two HTML programs demonstrating JavaScript concepts. The first program illustrates loops (for, while, and do-while) by displaying even numbers, a countdown, and a greeting. The second program showcases functions by allowing users to call a message function, calculate the sum of two numbers, and find the square of a number.

Uploaded by

sheoranpooja726
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

PROGRAM 5

A HTML program to demonstrate loops like for loop ,do while


loop ,while in java script.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Loop Demonstration</title>
<style>
body { font-family: Arial, sans-serif; }
.output { white-space: pre-wrap; border: 1px solid #ccc; padding: 10px; margin-
top: 10px; }
</style>
</head>
<body>
<h2>Loop Demonstration in JavaScript</h2>
<button onclick="runLoops()">Run Loops</button>
<div class="output" id="output"></div>

<script>
function runLoops() {
let result = "";

result += "For Loop (Even Numbers 2-10):\n";


for (let i = 2; i <= 10; i += 2) {
result += i + " ";
}

result += "\n\nWhile Loop (Countdown 5-1):\n";


let j = 5;
while (j >= 1) {
result += j + " ";
j--;
}

result += "\n\nDo-While Loop (Print Hello 3 times):\n";


let k = 0;
do {
result += "Hello\n";
k++;
} while (k < 3);

document.getElementById("output").innerText = result;
}
</script>
</body>
</html>

OUTPUT:
PROGRAM 6
A HTML program which demonstrate the use of functions in
java script.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript Functions Demonstration</title>
<style>
body { font-family: Arial, sans-serif; }
.output { white-space: pre-wrap; border: 1px solid #ccc; padding: 10px; margin-
top: 10px; }
</style>
</head>
<body>
<h2>JavaScript Functions Demonstration</h2>
<button onclick="showMessage()">Call Function</button>
<button onclick="calculateSum(5, 10)">Calculate Sum</button>
<button onclick="displaySquare(4)">Square of a Number</button>
<div class="output" id="output"></div>

<script>

function showMessage() {
document.getElementById("output").innerText = "Hello! This is a simple
function.";
}

function calculateSum(a, b) {
let sum = a + b;
document.getElementById("output").innerText = "Sum of " + a + " and " + b
+ " is: " + sum;
}

function displaySquare(num) {
let square = num * num;
document.getElementById("output").innerText = "Square of " + num + " is: "
+ square;
}
</script>
</body>
</html>

OUTPUT:

You might also like