0% found this document useful (0 votes)
297 views8 pages

Practical No.2 Develop Javascript To Use Decision Making and Looping Statements

The document discusses different JavaScript statements for decision making and looping. It provides code examples for if/else statements, if/else ladders, break, continue, for loops, while loops, do/while loops, and switch statements. Each code example outputs the result of applying the statement to evaluate conditions or iterate through a loop.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
297 views8 pages

Practical No.2 Develop Javascript To Use Decision Making and Looping Statements

The document discusses different JavaScript statements for decision making and looping. It provides code examples for if/else statements, if/else ladders, break, continue, for loops, while loops, do/while loops, and switch statements. Each code example outputs the result of applying the statement to evaluate conditions or iterate through a loop.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Practical no.

2
Develop Javascript To Use Decision Making And Looping
Statements

If-Else Statement:-

<html>
<body>
<script type="text/javascript">
var a
a=11
if(a%2==0)
document.write(a+ " is even number")
else
document.write(a+ " is odd number")
</script>
</body>
</html>

Output:-
If-Else Ladder:-

<html>
<body>
<script type="text/javascript">
var num = -12
if (num>0)
document.write(num+" is Positive number")
else if (num<0)
document.write(num+" is Negative number")
else
document.write(num+" number is zero")
</script>
</body>
</html>

Output:-
Break:-

<html>
<body>
<script type ="text/javascript">
var i;
for (i=0;i<=10;i++)
{
if (i==6)
{
break
}
document.write("<br>"+i)
}
</script>
</body>
</html>

Output:-
Continue:-

<html>
<body>
<script type ="text/javascript">
var a;
for (a=1;a<=7;a++)
{
if (a==4)
{
continue
}
document.write("<br>"+a)
}
</script>
</body>
</html>

Output:-
For Loop:-

<html>
<body>
<script type=" text/javascript">
var n
for(n=1;n<=10;n++)
document.write(n+ "<br>")
</script>
</body>
</html>

Output:-
While loop :-

<html>
<body>
<script type ="text/javascript">
var i=1
while(i<=10)
{
if(i%2==0)
document.write(i+ "<br>")
i++;
}
</script>
</body>
</html>

Output:-
Do-while Loop:-

<html>
<body>
<script type ="text/javascript">
var i=1
var n=10
do
{
document.write(i+"<br>")
i++;
}
while(i<=n)
</script>
</body>
</html>

Output:-
Switch Case:-

<html>
<body>
<script type= "text/javascript">
var num = 5
switch(num)
{
case 1:
document.write("One")
break;
case 2:
document.write("Two")
break;
case 3:
document.write("Three")
break;
case 4:
document.write("Four")
break;
case 5:
document.write("Five")
break;
}
</script>
</body>
</html>

Output:-

You might also like