+ 1
Can I use "or" in a switch statement of javascript?
Is the following syntax possible? var x = prompt() switch (x) { case 1 or 2 or 3 : document.write('abc'); break; case 4 or 5 or 6 : document.write('def'); break; }
2 ответов
+ 6
No, and neither you should do it this way, try using if-else statement instead, like
if([1,2,3].includes(x))
document.write("abc")
else if([4,5,6].includes(x))
document.write("def")
+ 1
Thanks!!