+ 1
What is wrong with my coding? Why alert option not coming.!!!!
var age = prompt("plz enter age"); switch(age){ case age < 18: alert("you are child"); break; case age > 18: alert("you are adult "); break; case age > 35: alert("you are getting older"); break; }
5 Respostas
+ 3
When you use prompt() the input is returned as a string. You need to convert the input to an int using parseInt()
https://www.w3schools.com/jsref/jsref_parseint.asp
+ 3
Also, switch doesn't work with conditionals like that.
You'd need to use if statements.
https://www.w3schools.com/js/js_switch.asp
+ 3
Just place the prompt inside the parseInt call
parseInt(prompt("plz enter age"));
+ 1
Ok Thanks bro
0
ChaoticDawg can you edit my code, and convert the output to an int using parselent.
Because i have no knowledge of int and parselent.