Task on “if..
else if”:
Write a javascript program to accept the marks from the student and display
the Grade by considering the following conditions with the help of if .. else if
statements.
1) If entered marks are above 100 then display: Please enter the marks less
than or equal to 100
2) If entered marks are exactly 100 then display: Grade is A+
3) If entered marks are between 90 to 99 then display: Grade is A
4) If entered marks are between 80 to 89 then display: Grade is B+
5) If entered marks are between 70 to 79 then display: Grade is B
6) If entered marks are between 60 to 69 then display: Grade is C+
7) If entered marks are between 50 to 59 then display: Grade is C
8) If entered marks are between 40 to 49 then display: Just pass
9) If entered marks are below 40 then display: Fail
Design
Program: [Link]
<!DOCTYPE html>
<html>
<head>
<title> if else if else </title>
</head>
<body>
<label> Enter marks: </label>
<input type="text" id="textbox1"><br><br>
<input type="submit" value="Grade" onclick="marks()"><br><br>
<p id="display" style="font-family: arial black; font-size: 20px;"></p>
<script>
function marks()
{
var marks=parseInt([Link])
if (marks>100)
{
[Link]("display").innerHTML="Enter marks lessthan or
equal to 100"
}
else if (marks==100)
{
[Link]("display").innerHTML="Grade is: A+"
}
else if (marks>=90)
{
[Link]("display").innerHTML="Grade is: A"
}
else if (marks>=80)
{
[Link]("display").innerHTML="Grade is: B+"
}
else if (marks>=70)
{
[Link]("display").innerHTML="Grade is: B"
}
else if (marks>=60)
{
[Link]("display").innerHTML="Grade is: C+"
}
else if (marks>=50)
{
[Link]("display").innerHTML="Grade is: C"
}
else if (marks>=40)
{
[Link]("display").innerHTML="Just Pass"
}
else
{
[Link]("display").innerHTML="Fail"
}
}
</script>
</html>
Output:
Next enter 100 marks
Next enter 99 marks
Like this check all marks
Task on “Multiple if”: Write a javascript program to check whether given
number is position or negative number and even or odd number by using
multiple if statements
Design:
Program: [Link]
<!DOCTYPE html>
<html>
<head>
<title> Multiple if example </title>
</head>
<body>
<label> Enter one number: </label>
<input type="text" id="textbox1"><br><br>
<input type="submit" value="Check" onclick="check()"><br>
<p id="print1" style="font-family: verdana; font-size:30;"></p>
<p id="print2" style="font-family: verdana; font-size:30;"></p>
<script>
function check()
{
var a=parseInt([Link])
if(a>=0)
{
[Link]("print1").innerHTML=a+" is positive number"
}
if(a<0)
{
[Link]("print1").innerHTML=a+" is negative number"
}
if(a%2==0)
{
[Link]("print2").innerHTML=a+" is an even number"
}
if(a%2!=0)
{
[Link]("print2").innerHTML=a+" is an odd number"
}
}
</script>
</body>
</html>
Output
Next, enter negative number
Homework
Interview questions:
a) when we will go for "if ... else if" statements
b) When we will go for "Multiple if" statements
c) What are the differences between "if .. else if" and "Multiple if"
Tasks:
Task1: Write four examples on "if... else if"
Task2: Write four examples on "Multiple if"