Hello. I try to use a switch statement, but it prints me only the default block code and I don’t understand why. 75 value doesn’t match with case 3 as it should. What is wrong with my code?
let response;
let score = 75;
let machineActive = false
switch (machineActive === “true”) {
case 0: score < 0 || score > 100
response = “This is not possible, an error has occurred.”;
break;
case 1: score < 20
response = “That was a terrible score — total fail!”;
break;
case 2: score < 40
response = “You know some things, but it’s a pretty bad score. Needs improvement.”;
break;
case 3: score < 70
response = “You did a passable job, not bad!”;
break;
case 4: score < 90
response = “That’s a great score, you really know your stuff.”;
break;
default: response = 'The machine is turned off. Turn it on to process your score.' }
console.log (`Your score is ${score}`)
console.log (response)
Your “case” lines are wrong. You don’t need the numbering and the rest should be before the colon. For example: case (score >= 0 && score < 20):
Furthermore your switch condition is always false, because you are strictly comparing a boolean to a string. It should simply be switch (true). Then the case with the true expression will be selected. To check if the machine is on, you should use an if block around the whole switch statement.