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 followed by
the words “LARGER NUMBER” in an information message dialog. If the numbers are
equal, output HTML text as “EQUAL NUMBERS”.
Source code:
<!-- Largest of three integers -->
<!doctype html>
<html>
<head>
<title>Largest of given three integers</title>
<script>
let a, b, c;
a = parseInt(prompt("Enter an integer",0));
b = parseInt(prompt("Enter another integer",0));
c = parseInt(prompt("Enter another integer",0));
if(a==b && a==c && b==c)
alert("ALL ARE EQUAL");
else if (a>b && a>c)
alert("a ("+a+") is the LARGEST among given three integers a, b and c ("+a+", "+b+", and
"+c+")");
else if(b>c)
alert("b ("+b+") is the LARGEST among given three integers a, b and c ("+a+", "+b+", and
"+c+")");
else
alert("c ("+c+") is the LARGEST among given three integers a, b and c ("+a+", "+b+", and
"+c+")");
</script>
</head>
<body>
<h2>Largest of given three integers</h2>
</body>
</html>
Write a program to display week days using switch case.
Source code:
<!-- Program to demonstrate SWITCH statement in JavaScript-->
<!doctype html>
<html>
<head>
<title>Demonstrating Switch in JavaScript</title>
</head>
<body>
<script>
switch(new Date().getDay())
{
case 0: alert("Sunday");
break;
case 1: alert("Monday");
break;
case 2: alert("TuesDay");
break;
case 3: alert("Wednes Day");
break;
case 4: alert("Thurs Day");
break;
case 5: alert("Fri Day");
break
case 6: alert("Satur Day")
break
}
</script>
</body>
</html>
Write a program to print 1 to 10 numbers using for, while and do-while loops.
Source code:
8_d.js
let i;
function display_while()
{
i=1;
while(i<=10)
{
document.write(i);
i=i+1;
}
}
function display_doWhile()
{
i=1;
do{
document.write(i);
i++;
}while(i<=10);
}
function display_for()
{
for(i=1; i<=10; i++)
{
document.write(i)
}
}
8_d.html
<!-- Program to demonstrate for, while, do-while statements in JavaScript -->
<!doctype html>
<html>
<head>
<title>Demonstrating for, while, and do-while statements in JavaScript</title>
</head>
<body>
<script src="8_d.js">
</script>
<h1>
Demo on FOR, WHILE and DO-WHILE
</h1>
<ul>
<li onclick="display_while()">While</li>
<li onclick="display_doWhile()">do-while</li>
<li onclick="display_for()">for</li>
</ul>
</body>
</html>
Develop a program to determine whether a given number is an ‘ARMSTRONG
NUMBER’ or not. [Eg: 153 is an Armstrong number, since sum of the cube of the
digits is equal to the number i.e.,13 + 53+ 33 = 153]
Source code:
<!-- Armstrong number verification -->
<!doctype html>
<html>
<head>
<title>Armstrong Number verification</title>
</head>
<body>
<h2>Armstrong number verification</h2>
<script>
let n, m, rem, sum;
sum = 0;
n = parseInt(prompt("Enter an integer to be verified !",0));
m = n;
while(n>0)
rem = Math.floor(n%10);
sum = sum + rem*rem*rem;
n = n/10;
if(sum==m)
alert("Given number, "+m+" is an armstrong number !");
else
alert("Given number, "+m+" is not an armstrong number !");
</script>
</body>
</html>
Write aprogram to print data in object using for-in, for-each and for-of loops
Source code:
<!--Program to demonstrate for loop variations in JavaScript -->
<!doctype html>
<html>
<head>
<title>Demonstrating For loop variations</title>
</head>
<body>
<h1>For Variations</h1>
<script>
let arr = [10,20,15,25,20];
let student = {
name:"Ram",
age:19,
gender:"Male",
course:"B.Tech.",
branch:"CSE",
year:1,
sem:1
document.write("<hr/><b>For Of</b><br/>")
let text;
for(let x of arr)
document.write(x + "<br/>")
document.write("<hr/><b>For In</b><br/>");
for(let key in student)
document.write(student[key]+"<br/>")
document.write("<hr/><b>For In to Access an Array</b><br/>");
for(let x in arr)
document.write(x+":"+arr[x]+"<br/>");
document.write("<hr/><h3>For Each</h3>")
let marks = [90,91,89,100,92,95],tot=0, txt="";
marks.forEach(findSum);
function findSum(curr,index,m)
if(m[index]<=95)
m[index] = curr + 5;
document.write(marks)
</script>
</body>
</html>