Basic Javascript Tutorial: switch statement. Basic Tutorial: switch
The format of the stwith statement is generally as follows:
Copy codeThe Code is as follows:
Switch (expression ){
Case value: statement1
Break;
Case value2: statement2
Break;
....
Case value: statement
Break;
Default: statement;
If expression is equal to case, statament is executed.
Keyword break: the code jumps out of the switch.
If there is no keyword break, the Code continues to execute the next situation. Keyword default is the result of execution when the value of all expressions is not equal to the value.
Copy codeThe Code is as follows:
Iwork = parseInt (prompt ("enter a value from 1 to 5 "));
Switch (iwork ){
Case 1: document. write ("Monday ")
Break;
Case 2: "Week 2"
Break;
Case 3: "week 3"
Break;
Case 4: "Week 4"
Break;
Case 5: "day of the week"
Break;
Default: "enter a reasonable value ";