JavaScript Switch Statement Problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

JavaScript Switch Statement Problem

var yourname = prompt("Hi, Im Bob, what is your name?"); alert("Hi " + yourname + " Nice to meet you"); var yourage = prompt("How old are you?"); switch(yourage) { case(yourage <= "10"): alert("Well, Looks like your pretty young, you still have a lot to learn"); } The problem is the case(yourage <="10"); alert("the message") If I enter 10, or a age less then 10, a alert box does not pop up even thought it is less than or equal to, I would lobe it if someone could help me please, thanks.

2nd Feb 2018, 4:13 PM
Luke.Pod
1 Answer
+ 2
actually you got the syntax wrong. you don't put conditions in the cases. you gotta use results, for example case 17: alert("no"); break; case. 18: alert("you can enter this site"); break; case Math.pow(9,2): alert("too old"); break;
2nd Feb 2018, 4:35 PM
voidneo