Switch


#1

Does anyone know why I get "unexpected token" when I try to run this code? Thanks.

`var user = prompt("How much do you want to win the lottery? A lot? A little? Not Sure?").toUpperCase();

switch(user){
case 'A lot':
console.log("OK, ready?");
break;
case 'A little':
console.log("Play something else?");
break;
case 'Not Sure';
console.log("Let's play");
break;
default:
console.log("Ready");
};

`


#2

It means that you wrote something that can't exist in that location based on what's been written so far. For example, if you write = then you can't write another: = =, it's not allowed there.
If you look at the full error then it says which token it is. You can also run it in another interpreter, one that includes line numbers in the error messages. You could install node.js on your computer and run it with that, or you could use node.js at repl.it .. you can also run it with your browser but you'll have to figure that out yourself as it's browser dependent or at least i bit more involved.


#3

Thanks but my code is so close to the example, punctution and all that I don't see what the unexpected token is. It does not look as if I have forgotten anything.


#4

You can see which it is in the error message. I also gave suggestions on how to find out where it is.


#5

I have no more details in my error msg.


#6

Running the code in the learning environment, I guess you don't, that error message looks incomplete to me.

That still leaves my other suggestion about running it in an environment with more verbose error messages!