Home > Web Front-end > JS Tutorial > Javascript Basics Tutorial: Switch Statement_Basic Knowledge

Javascript Basics Tutorial: Switch Statement_Basic Knowledge

WBOY
Release: 2016-05-16 16:19:34
Original
1325 people have browsed it

The format of the stwith statement is generally as follows:

Copy code The code is as follows:

switch (expression){
case value :statement1
          break;
case value2 :statement2
          break;
....
          case value: statement
          break;
Default :statement;

Each case means that if the value of expression is equal to case, then the statute is executed.

The keyword break causes the code to jump out of switch.

If there is no keyword break, the code will continue to execute the next situation. The keyword default is the result of execution when the value of all expressions is not equal to the value value.

Copy code The code is as follows:

iwork = parseInt(prompt("Please enter a value from 1-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 : "Sunday 5"
              break;
                                                                                                                                                                                                                              “Please enter the reasonable value”;
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template