Because score
having the integer value of 3
will never become boolean true
or false
, as (score < 1)
is false
and (score < 5)
is true
.
switch
statement checks if the passed variable (or value) equals to one of the cases, i.e.:
switch (score) {
case 1:
// score is 1
break;
case 3:
// score is 3
break;
case true:
// score is true
break;
default:
// neither of above
}
What you are trying to achieve with switch
statement can be done as follows:
switch (true) {
case (score < 1):
alert('DUFF');
break;
case (score < 5):
alert('AWESOME');
break;
default:
alert('NOPE');
}