Submissions will no longer be placed on the leaderboard. You may still attempt this problem for practice.

The switch statement evaluates an expression, matches the expression's value to a case clause, and executes the statements associated with that particular case.

Switch Statements

Here's a useful video on the topic:

A switch statement first evaluates its expression.

Then, it looks for the first case clause whose expression matches the same value as the result of the input expression (using strict comparison, ===).

Finally, it transfers control to that clause.

Syntax:

    switch (expression) {
      case value1:
        //Statements executed when the result of expression matches value1
        [break;]
      case value2:
        //Statements executed when the result of expression matches value2
        [break;]
      ...
      case valueN:
        //Statements executed when the result of expression matches valueN
        [break;]
      default:
        //Statements executed when none of the values match the value of the expression
        [break;]
    }

With each case label, there is an optional break statement to ensure that the program breaks out of the switch once the matching statement is performed and continues execution at the statement following the switch.

If the break is omitted, the program continues execution at the next statement within the switch statement.

Example

switch (day) {  //day is an integer varying from 0 to 6.
    case 6:
        text = "Today is Saturday";
        break;
    case 0:
        text = "Today is Sunday";
        break;
    default:
        text = "Looking forward to the Weekend";
} 

Task

You are given a variable, . Your task is to print:

- ONE, if is equal to .
- TWO, if is equal to .
- THREE, if is equal to .
- FOUR, if is equal to .
- FIVE, if is equal to .
- SIX, if is equal to .
- SEVEN, if is equal to .
- EIGHT, if is equal to .
- NINE, if is equal to .
- PLEASE TRY AGAIN, if is none of the above.

Note: Do not declare the variable ; it is declared inside our code checker. Use console.log to print statements to the console.

Line: 1 Col: 1
  1. Challenge Walkthrough
    Let's walk through this sample challenge and explore the features of the code editor.1 of 6
  2. Review the problem statement
    Each challenge has a problem statement that includes sample inputs and outputs. Some challenges include additional information to help you out.2 of 6
  3. Choose a language
    Select the language you wish to use to solve this challenge.3 of 6
  4. Enter your code
    Code your solution in our custom editor or code in your own environment and upload your solution as a file.4 of 6
  5. Test your code
    You can compile your code and test it for errors and accuracy before submitting.5 of 6
  6. Submit to see results
    When you're ready, submit your solution! Remember, you can go back and refine your code anytime.6 of 6
  1. Check your score