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

JavaScript Control Structures Explained

Uploaded by

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

JavaScript Control Structures Explained

Uploaded by

khush7255
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Punjab Institute of Management &

Technology

JavaScript
Lecture-02

Amit Kapoor
Dean, Academics &
Head, Department of Computer Applications
Punjab Institute of Management & Technology
If else statment

[Link] [Link]
var a,b,c; <html>
a=parseInt(prompt("enter first value")) <head>
b=parseInt(prompt("enter second value")) <script type="text/javascript" src =“[Link]">
if(a>b) </head>
[Link]("<br> a greater") <body>
else if(a<b) </script>
[Link]("<br> b greater") </body>
else </html>
[Link]("<br> both same")

Friday 3 October 2025 Amit Kapoor, Assistant Professor, PIMT 06:22:59 AM 2


<html>
<head> Switch Statement Example
<title> Menu Driver Program </title>
<script language="javascript">
function fillBackgroundColor(a) <body>
{ <form name=myform>
switch(a) r : red <br>
{ g : green <br>
case 'r': b : blue <br>
[Link]="red"; Enter Your Choice <input type="text" name=txt id="txt" size=20>
break; <input type="button" value=submit
case "g": onclick=fillBackgroundColor([Link])>
[Link]="green"; </form>
break; </body>
case "b": </html>
[Link]="blue";
break;
default:
alert("wrong choice");
}
}
</script>
</head>
Friday 3 October 2025 Amit Kapoor, Assistant Professor, PIMT 06:22:59 AM 3
While loop
<html>
<head> <form name="myform">
<script language="javascript"> <input type="text" name="n1" id="n1"
function factorial() placeholder="Enter any number"><br>
{ <input type="text" name="n2" id="n2"><br>
var n, temp; <input type="button" name="b1" value="Factorial"
n=parseInt([Link]("n1").value); onclick="factorial()"><br>
temp=n; </form>
fact=1; </html>
while(n!=0)
{
fact=fact*n;
n--;
}
[Link]("n2").value="Factorial of "+ temp+ " is "+ fact;
}
</script>
</head>
Friday 3 October 2025 Amit Kapoor, Assistant Professor, PIMT 06:22:59 AM 4

You might also like