Help: Do you see any syntax issue?

When I put score=60, the corresponding content of “response” doesn’t return to me? Same for other conditions, except the ‘default’ one. Do you see any syntax issue in “switch” structure here?

let response;
let score = 60;
let machineActive = true;

if(machineActive) {

    case score<0||score>100:
    response='This is not possible, an error has occurred.';

    case score>=0 && score<=19:
    response='That was a terrible score — total fail!';

    case score>=20 && score<=39:
    response='You know some things, but it\'s a pretty bad score. Needs improvement.';

    case score>=40 && score<=69:
    response='You did a passable job, not bad!';

    case score>=70 && score<=89:
    response='That\'s a great score, you really know your stuff.';

    response='What an amazing score! Did you cheat? Are you for real?';
} else {
  response = 'The machine is turned off. Turn it on to process your score.';

you are trying to compare the expression in the parentheses to the values of the cases, so score will never equal a boolean value , try using switch(true) instead it should work

I suggest you review how a switch statement works. As the comparison you are doing here is score === score < 10 || score > 100
I really suggest you review how a switch statement work. Or to use an if/else chain

1 Like