Professional Documents
Culture Documents
The JavaScript switch statement is used to execute one code from multiple
expressions. It is just like else if statement that we have learned in previous
lesson. But it is convenient than if..else..if because it can be used with
numbers, characters etc.
1. switch(expression){
2. case value1:
3. code to be executed;
4. break;
5. case value2:
6. code to be executed;
7. break;
8. ......
9.
10. default:
11. code to be executed if above values are not matched;
12. }
For example:
<!DOCTYPE html>
<html>
<body>
<script>
var grade='A';
var result;
switch(grade){
case 'A':
result="A Grade";
break;
case 'B':
result="B Grade";
break;
case 'C':
result="C Grade";
break;
default:
result="No Grade";
}
document.write(result);
</script>
</body>
</html>
Learning Objectives
At the end of the lesson, the students are expected to:
1. Perform JavaScript switch statement.
Activity 01:
Directions: Perform the following codes below:
1. var day;
switch (new Date().getDay()) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
break;
default:
day = "Unknown Day";
}
2. var text;
switch (new Date().getDay()) {
case 6:
text = "Today is Saturday";
break;
case 0:
text = "Today is Sunday";
break;
default:
text = "Looking forward to the Weekend";
}
Prepared by:
Noted:
_______________________
Activity 1: Rubrics
Points Description
10 The student successfully executes the program without guidance or supervision.
The student successfully executes the program with very little supervision and
9
guidance.
The student successfully executes the program with moderate supervision andguidance.
8
The student was not able to execute the program but shows eagerness to accomplishthe
7
activity.
5 The student was not able to execute the program due to lack of interest in the activity.