Practical - 2
Aim:
Implement various programs to understand various JS controls.
Program 2.1
To write a JS program using the if statement.
CODE:
FILE 1 HTML(P 2_1.HTML)
<html>
<head>
</head>
<body>
<script>
var x=10;
if(x>0){
document.write("x is greater than zero");
}
</script>
</body>
</html>
OUTPUT:
Program 2.2
To write a JS program using the if…….else statement.
CODE:
FILE 1 HTML(P 2_2.HTML)
<html>
<head>
</head>
<body>
<script>
var a = 6
if(a%2==0){
document.write("number is even");
}
else{
document.write("number is odd");
25012011139_TAHIR BHATI 7
, }
</script>
</body>
</html>
OUTPUT:
Program 2.3
To write a JS program using the else…….if statement.
CODE:
FILE 1 HTML(P 2_3.HTML)
<html>
<head>
</head>
<body>
<script>
var a=3
switch (a){
case 1: document.write("monday");
case 2:document.write("tuesday");
case 3:document.write("wednesday");
}
</script>
</body>
</html>
OUTPUT:
Program 2.4
To write a JS program using switch statement.
CODE:
FILE 1HTML(P 2_4.HTML)
<html lang="en">
<head>
</head>
<body>
<script>
var marks=70
if(marks>=75){
document.write("distinction");
}
else if (marks>=65){
25012011139_TAHIR BHATI 8
Aim:
Implement various programs to understand various JS controls.
Program 2.1
To write a JS program using the if statement.
CODE:
FILE 1 HTML(P 2_1.HTML)
<html>
<head>
</head>
<body>
<script>
var x=10;
if(x>0){
document.write("x is greater than zero");
}
</script>
</body>
</html>
OUTPUT:
Program 2.2
To write a JS program using the if…….else statement.
CODE:
FILE 1 HTML(P 2_2.HTML)
<html>
<head>
</head>
<body>
<script>
var a = 6
if(a%2==0){
document.write("number is even");
}
else{
document.write("number is odd");
25012011139_TAHIR BHATI 7
, }
</script>
</body>
</html>
OUTPUT:
Program 2.3
To write a JS program using the else…….if statement.
CODE:
FILE 1 HTML(P 2_3.HTML)
<html>
<head>
</head>
<body>
<script>
var a=3
switch (a){
case 1: document.write("monday");
case 2:document.write("tuesday");
case 3:document.write("wednesday");
}
</script>
</body>
</html>
OUTPUT:
Program 2.4
To write a JS program using switch statement.
CODE:
FILE 1HTML(P 2_4.HTML)
<html lang="en">
<head>
</head>
<body>
<script>
var marks=70
if(marks>=75){
document.write("distinction");
}
else if (marks>=65){
25012011139_TAHIR BHATI 8