Answer the question
In order to leave comments, you need to log in
The problem with the switch-case construct. How to decide?
I’ve been sitting here for an hour now, I can’t understand what the problem is
======================================= ===========
let chs = prompt('Enter a number between 1 and 31');
switch(chs) {
case (chs < '10' && chs > '0'):
alert('You are in the top ten');
break;
case (chs > '20' && chs < '10'):
alert('You are in the second ten');
break;
case (chs > '30' && chs < '20'):
alert('You are in the top ten');
break;
default:
alert('This number is not supported');
break;
Answer the question
In order to leave comments, you need to log in
To do this, you need to replace the line:
switch(chs) {
with:
And also pay attention to the comparison signs in the conditions
switch(true) {
Switch is very slow with conditions, use if or explicitly set the value of the variable. If, as you want, then in switch you need to pass true and not a variable, then case will be executed, which will be true
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question