Missed break in switch statment


#1

I'm getting an error but I can't find how to fix it.


The exercise is https://www.codecademy.com/courses/javascript-beginner-en-qDwp0/1/4?curriculum_id=506324b3a7dffd00020bf661#


The error is "Make sure you have a break statement for each case."


switch('0') {
    case '0':
        console.log("First case.");
        break;
    case '1':
        console.log("Second case.");
        break;
    case '2':
        console.log("Third case.");
        break;
    case '3':
        console.log("Forth case.");
        break;
    default:
        console.log("Default mode.");
        break;
}

Here is a screenshot - http://image.prntscr.com/image/3d2c2fb4db3f4bfaa2d39b5b1fc5868e.png


#2

Try switch(answer) instead of switch('0').

The value of the answer is compared with the values of each case. If there is a match, the associated block of code is executed.


#3

I've tried. Doesn't work.
Here's a screenshot


#4

var answer = prompt("Add your question here!");

switch(answer) {
  case '1':
    console.log("1");
    break;
  case '2':
    console.log("2");
    break;
  case '3':
    console.log("3");
    break;
  default:
    console.log("default");
    break;
}

The prompt() method displays a dialog box that prompts the visitor for input. The prompt() method returns the input value if the user clicks "OK". If the user clicks "cancel" the method returns null. But in our case returns 'default' into console.


#5

I know how prompt works. The question is how to fix missing break error


#6

var number = '2';

switch(number) {
...
}

You always have number = '2' and '2' as a result. Try to use prompt() method and swicth() correctly. Because your switch's body is correct. You have problem only with condition. Did you tried my code? Please, look to my code, it works.


#7

Anyway, Screenshot


#8

Actully your code is completely fine.but here in codecademy you have to change all the words named case inside console.log for SCT(Submission Correctness Test).

you can use

console.log("First Case."); //capital C


#9

I would try not using break; in default part.


#10

Yeah, it is. But wtf wrong with Codecademy?!
(scr)


#11

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.