+ 6
How do i put switch inside if condition??
I want to put switch inside if condition. And the switch has a variable that contain a value of Number(prompt()). If i try to run the code, nothing appears. See what i mean: var s1 = Number(prompt("Which Number?")); if(s1 == Number) { switch(s1) { case "1": document.write(" I am number 1"); break; case "2": document.write(" I am number 2"); break; case "3": document.write(" I am number 1"); break; default: document.write("No number found"); } }
2 Respostas
+ 2
if(typeof(s1)=="number")
+ 1
Currently you are checking if a value is equal to function. Check if s1 is not NaN.
if (!isNaN(s1)) {
}