As far as I understand it, when you use a switch statement, the variable inside the parentheses after switch is the thing you are testing the value of, then the values inside the parentheses after the case statements are the different values you are testing for.
In a really simple case such as this:
switch (happy) {
case (true):
response = 'I am happy';
break;
case (false):
response = 'I am sad';
break;
}
This works fine, as here we are testing whether happy is equal to true or false, and then doing something as a result.
In more complex cases, like in this assessment, this kind of structure doesn’t work.
If our value to test is set as score, how do we then write the condition of score >= 0 && score < 20 without mentioning score? Instead, we write true as a kind of dummy test value, then write the entire test inside the cases, including the value to test.
We could do the same thing with our happy/sad example like this:
switch (true) {
case (happy === true):
response = 'I am happy';
break;
case (happy === false):
response = 'I am sad';
break;
}
or
switch (true) {
case (happy):
response = 'I am happy';
break;
case (!happy):
response = 'I am sad';
break;
}
But this is not necessary in this simple case.