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

Assignment No 2 Final Re

Uploaded by

Karan Mohite
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 views9 pages

Assignment No 2 Final Re

Uploaded by

Karan Mohite
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/ 9

Assignment No 2

Q1. Decision making statement


1.if statement
<html>
<head>
<title>If Statement</title>
<script>
var age=20;
if(age>=18)
{
document.write("You are an adult");
}
if(age<18)
{
document.write("You are not an adult");
}
</script>
</head>
</html>

Output:
2.if else statement
<html>
<head>
<title>IfElse Statement</title>
<script>
var age=17;
if(age>=18)
{
document.write("You are an adult");
}
else
{
document.write("You are not an adult");
}
</script>
</head>
</html>

Output:
3. if else if statement
<html>
<head>
<title>IfElseIf Statement</title>
<script>
var a=10;
var b=20;
if(a==b)
{
document.write("a&b are equal");
}
else if(a<b)
{
document.write("a is less than b");
}
else
{
document.write("a is greater than b");
}
</script>
</head>
</html>

Output:
4.nested if statement
<html>
<head>
<title>NestedIf Statement</title>
<script>
var a=10
if(a==10)
{
document.write("a is 10");
document.write("<br>");
}
if(a<20)
{
document.write("a is smaller than 20");
}
else
{
document.write("a is greater than 20");
}
</script>
</head>
</html>

Output:
5.switch case statement
<html>
<head>
<title>Switch Case Statement</title>
<script>
var day=5;
switch(day)
{
case 1:
document.write("Monday");
break;
case 2:
document.write("Tuesday");
break;
case 3:
document.write("Wednesday");
break;
case 4:
document.write("Thursday");
break;
case 5:
document.write("Friday");
break;
case 6:
document.write("Saturday");
break;
case 7:
document.write("Sunday");
break;
default:
document.write("Invalid");
}
</script>
</head>
</html>

Output:
2.Looping Statement

1.for loop
<html>
<head>
<title>ForLoop</title>
<script>
var i;
for(i=1;i<=10;i++)
{
document.write("The number is="+i);
document.write("<br>");
}
</script>
</head>
</html>

Output:
2.While Loop
<html>
<head>
<title>While Loop</title>
<script>
var i =0,j=1,k;
document.write("<br>Using while loop");
document.write("<br>Fibonacci series less than 40 ");
while(i<40)
{
document.write(i+"<br>");
k=i+j;
i=j;
j=k;
}
</script>
</head>
</html>

Output:
3.Do While Loop
<html>
<head>
<title>Do While Loop</title>
<script>
var i=0;
document.write("Number is less than 20");
do
{
document.write("<br>"+i);
i++;
}while(i<=20)
</script>
</head>
</html>

Output:

You might also like