What missing break statement?


#1




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 );}


#2

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

did not work either.


#3

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

Blocking the code for each case did not work either.


#4

All your switch statements should have this format

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

This is just an example


#5

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


#6

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.

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

#7

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?':
    console.log("Dave");
    break;
        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");
      break;
      default:
      console.log("Did you ask a question?")
  
}

#8

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


#9

Rearranging the whitespace between javascript parts had no effect.

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 );
        break;
    }

#10

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

console.log()

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.


#11

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


#14

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


#15

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