Unexpected Token on 8. All on Your Own


#1

Hello, can someone please tell me why this code doesn't work? I keep getting "Error: Unexpected Token :"

var myTest = prompt("What is one color of the rainbow?");

switch(myTest) {
  case: 'red'
    console.log("Sure is");
    break;
  case: 'orange'
   console.log("Yep");
    break;
  case: 'yellow'
   console.log("Yeah");
    break;
  case: 'green'
   console.log("For sure");
    break;
  case: 'blue'
   console.log("Definitely");
    break;
  case: 'indigo'
   console.log("Affirmitive");
    break;
  case: 'violet'
   console.log("Yes");
    break;
  default:
    console.log("Nope.");
}

#2

Is this your entire code? From what I see this doesn't have an error attached to it.


#3

Yes, this is the entire thing.


#4

This is the error message:

SyntaxError: Unexpected token :


#5

From Firefox's scratchpad (shift F4):

/*
Exception: SyntaxError: expected expression, got ':'
@Scratchpad/1:4
*/

#6

All I can go with is that you'll need to refresh the page. I can't find anything wrong with your code.


#7

Well, i dont have a nice english but,
the error is in the case, because do you need to write: " case 'yellow': ", not "case: yellow" do you understand the error?
Bye.


#8

Thanks @moty123, that worked!


#9

You're welcome! And try hard!


#10

I agree with moty123