Test yout skills: Conditionals

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)

Hi @deliadodenciu and welcome to the community :wave:

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.

Does that make sense? If not just ask. :slightly_smiling_face:

See you,
Michael

Hi Michael,

Thank you so much for help. I will try later to solve the problem and I will tell you if it worked.

Have a great weekend.:grin:

Kind regards,
Delia

1 Like

Hello Michael,

I used what you told me to do and now I understand how it works. Thank you very much. :slight_smile:

Delia

În vin., 14 apr. 2023 la 10:01, Michael Koch via Mozilla Discourse <notifications@discourse.mozilla.org> a scris:

1 Like

I’m glad to hear that. :slightly_smiling_face:

If you have any more exercises you want me to look at, feel free to come back.

By the way, your email address is visible in your post. It ended up in the optional “name” field of your profile. I recommend removing it.