I was trying to solve the problem Conditionals 3 from the Mozilla Foundation website. The thing is, the activity asks to use only Switch statements inside the if(machineActive). I solved it using if-else, but once I tried to use the switch statement the console shows the default message I set, "Something must be wrong", no matter what value the score variable gets. Any time I change the cases just the default message is being shown.
What's the correct way to use switch statements in this case? The if-else is the most appropriate choice, but I want to stick with the task's rules this time.
let response;
let score = 75;
let machineActive = true;
if(machineActive) {
switch(score){
case (score<=100 && score>=90):
response = "What an amazing score! Did you cheat? Are you for real?";
break;
case (score<=89 && score>=70):
response = "That\'s a great score, you really know your stuff.";
break;
case (score<=69 && score>=40):
response = "You did a passable job, not bad!";
break;
case (score<=39 && score>=20):
response = "You know some things, but it's a pretty bad score. Needs improvement.";
break;
case (score<=19 && score>=0):
response = "That was a terrible score — total fail!";
break;
default:
response = "Something must be wrong";
}
} else {
response = 'The machine is turned off. Turn it on to process your score.';
}
Aucun commentaire:
Enregistrer un commentaire