What missing break statement?


More practice with switch

I thought maybe changing the code's spacing and the exercise's identifier (from 'answer') could help, but no.
"Oops, try again.\ Make sure you have a break statement for each case."

var response = prompt( "testing..." );
switch( response ){
case'a':console.log( "first case" );break;
// Add your code here!
case'b':console.log( "second case" );break;
case'c':console.log( "third case" );break;
case'd':console.log( "fourth case" );break;
default:console.log( "answer: " + response );}


default:console.log( "answer: " + response );break;

did not work either.


case'd':{console.log( "fourth case" );break;}

Blocking the code for each case did not work either.


All your switch statements should have this format

switch(resonse) {
  case 'Any string you want':
    console.log("any string you want");

This is just an example


That's what I had before the {} blocking.


You put the colon at the wrong place it should be at the end of the console.log as well.

And your default should look like this.

      console.log("Did you ask a question?")


Put it all together and you should get a piece if code like this

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

switch(answer) {
  case 'What is your name?':
        case 'Why do you like coding?':
      console.log("Because it is a self empowered platform in which you an do just about anything digitally! Well apart from get a girlfriend, or beat a bully");
      console.log("Did you ask a question?")


This is just an example of what your code should look like.


Rearranging the whitespace between javascript parts had no effect.

var response = prompt( "testing..." );

switch( response ){
    case 'a':
        console.log( "first case" );
// Add your code here!
    case 'b':
        console.log( "second case" );
    case 'c':
        console.log( "third case" );
    case 'd':
        console.log( "fourth case" );
        console.log( "answer: " + response );


I've been looking at this for a little while, and I found something that seems to make your code work... but I'm not sure why. In all of your


statements, delete the word case. Do not delete the actual cases under the switch statement, only in the console.logs. It accepts it for me when those are deleted, but it fails when those words are still there. This would appear to be a bug.


After replacing all 'case' substrings with 'choice', it is OK. Thank you. A bug :open_mouth:?


@roched, in the code that you just pasted, you have one break to many. Take out the break right after the default.


This topic was automatically closed after 10 hours. New replies are no longer allowed.