Need assessment for “Conditionals skill test"

Peace to all.

Here is the tasks

Here is the solution :

Thank you all for your responsiveness!

Hello @rab_Allaha

Congratulations tasks 1,2 and 4 are correct!

Here are two simplifications and a hint for task 3:

  • Task 2: You could just write if (machineActive) { instead of if (machineActive === true) { because the variable itself is already true of false.
  • Task 3: You still have if...else if...else statements in your code. Those should be completely replaced by the switch statement. It should look something like this:
      if(machineActive) {
    	switch (true) {
    	  case (/* What goes in here? */):
    	    response = 'That was a terrible score — total fail!';
    	    break;
    	  case (/* What goes in here? */):
    	    response = 'You know some things, but it\'s a pretty bad score. Needs improvement.';
    	    break;
          ...
    	}
    } else {
      response = 'The machine is turned off. Turn it on to process your score.';
    }
    
  • Task 4: To avoid duplication you could put the pwdResult assignment at the beginning of the line:
    pwdResult = pwd === 'cheese' ? 'The password is correct' : 'Incorrect password';
    
    This works, because the assignment is the last thing that happens after the ternary operator is evaluated.

I hope that helps!
Michael

2 Likes

Hello @mikoMK. I have tried to correct these errors, if it is not difficult, can you check the solutions again? Thanks for the help :slight_smile:

1 Like

Great work on the update, @rab_Allaha!

Now it’s perfect! It’s rather unusual for a switch statement to have a fixed value in switch (...) and conditions in case (...), but as we saw in this exercise it’s completely valid and works.

Happy coding,
Michael