+ 1
Why does my switch case statement only execute the default case when i ask a user input for the expression?
var rll=window.prompt("Write a number!"); switch(rll){ case 1: alert("Ichi"); break; case 2: alert("Ni"); break; default: alert("N/A"); }
3 Antworten
+ 5
This is because the input is a string, and your case is an integer
Try : case "1",
Or convert the input to an integer using parseInt
https://code.sololearn.com/WeO9weNgnt0m/?ref=app
+ 1
seems like switch care about the data type. try
switch(parseInt(rll))
0
Thanks