Test your skills: Conditionals

Hello everyone

hope that everything going fine with all of you

for the third question why you asked us to use switch here cause it cost a lot of code

it make me write
switch (score){
case 0:
case 1:
case 2:
.
.
.
case 18:
case 19:
response = “That was a terrible score — total fail!”;
break;

and the same thing for the rest of values

is there any better way to use the switch to solve that one or not
and if not can you change the questions so it be more reasonable to use the switch for it

thanks again and have a nice day

Hello everyone

i just got another idea to decrease the code but i still need to use some if statement for it

if(score===100){
response = “What an amazing score! Did you cheat? Are you for real?”;
}
else if (score <0){
response = “This is not possible, an error has occurred.”;
}
else {
switch (Math.trunc(score/10)){

case 0:
case 1:
response = “That was a terrible score — total fail!”;
break;

case 2:
case 3:
response = “You know some things, but it’s a pretty bad score. Needs improvement.”;
break;

case 4:
case 5:
case 6:
response = “You did a passable job, not bad!”;
break;

case 7:
case 8:
response = “That’s a great score, you really know your stuff.”;
break;

case 9:
response = “What an amazing score! Did you cheat? Are you for real?”;
break;

/* the following fail if the score was less from -1 to -9 as it turn to go to -0 which is 0 also so default option can be removed
default:
response = “This is not possible, an error has occurred.”;
*/
}

}

have a nice day everyone

Hi @justsomeone !

switch statements are tricky; you actually don’t need to do this — have a look at our official answer: https://github.com/mdn/learning-area/blob/master/javascript/building-blocks/tasks/conditionals/marking.md#task-3

This earlier post of mine attempts to explain why this works: Assessment wanted Conditionals 3

thanks alot @chrisdavidmills

you always there for all of us

wish you the best and have a nice day

@justsomeone you too :wink:

thanks :slight_smile: