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) {

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

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

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

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

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

    default:
    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.';
}

hi,
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