Page 193 - Web Applications (803) Class 12
P. 193
Flow diagram:
true
condition 1 Statement 1
false
true
condition 2 Statement 2
false
true
condition 3 Statement 3
false
Statements outside the if-else if-else block
Example:
<html>
<body>
<script>
var perc=73.5;
if (perc>=90)
document.write("Excellent!Grade A");
else if (perc >=75 && perc <90)
document.write("Good Work! Grade B");
else if (perc >=60 && perc <75)
document.write("Average. Grade C");
else if (perc>=40 && perc<60)
document.write("Grade D");
else
document.write("Work Hard. Grade E");
</script>
</body>
</html>
Output of the preceding program is as follows:
The switch Statement
The switch statement is used to select one of the many code blocks that must be executed. Only one
evaluation of the switch expression is performed, and its value is compared to the values/labels of each case.
The associated code block is executed if a match is detected; else, the default code block is executed.
Web Scripting—JavaScript 191

