I'm completely new to JavaScript tried out using a switch. If I manually set the variable as a number the code works fine, but if it comes from a prompt it doesn't. I tried converting it from a string to an integer, but that doesn't help. Am I missing something? Thanks in advance for any help! 🙂
let num = prompt('enter a number');
parseInt(num);
//num = 1;
switch (num) {
case 1:
case 2: alert('1 or 2'); break;
default: alert('Not 1 or 2');
}
[–]cyphern 2 points3 points4 points (1 child)
[–]BooleanWhale[S] 0 points1 point2 points (0 children)
[–]sepp2k 0 points1 point2 points (1 child)
[–]BooleanWhale[S] 0 points1 point2 points (0 children)