+ 1
javascript switch
let age = prompt("Enter Your age: ") age = Number.parseInt(age) switch (age) { case age < 0: console.log('Invalid age...') break; case age > 0 && age < 18: console.log('You can\'t vote') break; default: console.log('You can vote') } // not able to find correct ans always showing "You can vote"
2 Answers
+ 4
Now run the code:-
let age = prompt("Enter Your age: ")
age = parseInt(age)
switch (true) {
case age < 0:
console.log('Invalid age...')
break;
case age > 0 && age < 18:
console.log('You can\'t vote')
break;
default:
console.log('You can vote')
}
+ 1
Thanks @sakshi
Its working :)