Basic Javascript Tutorial: switch statement. Basic Tutorial: switch

Source: Internet
Author: User

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 ";

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.