Javascript

Javascript loop programs

1. Print 1-10 numbers using FOR loop program

<html>
<head>
<title> Javascript looping program </title> 
</head>
<body>
<script language="javascript">
var i
document.write("<h1>"+"FOR Looping program" +"</h1>")
for(i=1; i<=10; i++)
{
document.write(i+"<br>")
}
</script>
</body>
</html>

2. WHILE Loop using Javascript

<html>
<head>
<title> Javascript while loop program </title> 
</head>
<body>
<script language="javascript">
var i=1
document.write("<h1>"+"WHILE Loop program" +"</h1>")
while(i<=10)
{
document.write(i"+<br>")
i++
}
</script>
</body>
</html>

3. DO WHILE Loop using Javascript

<html>
<head>
<title> Javascript while loop program </title> 
</head>
<body>
<script language="javascript">
var i=1
document.write("<h1>"+"DO WHILE Loop program" +"</h1>")
do
{
document.write(i"+<br>")
i++
}
while(i<=10);
</script>
</body>
</html>

4. Largest of two numbers

<html>
<head>
<title> Using Javascript </title>
</head>
<body>
<script language="javascript">
var a,b
a=prompt("Enter a value:")
b=prompt("Enter b value:")
if(a>b)
document.write("a is big")
else
document.write("b is big")
</script>
</body>
</html>
SKB

Leave a Reply

Your email address will not be published. Required fields are marked *