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

Javascript Basics Tutorial: Switch Statement_Basic Knowledge

WBOY
WBOYOriginal
2016-05-16 16:19:341256browse

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”;
Statement:
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