Assessment wanted for Conditionals 1-4 skill tests

Hello everyone!

Continuing my journey through JavaScript I have just completed the tests under Conditionals. I would really appreciate any feedback for the logic/methods I used.

Conditionals 1:
I was a bit confused by the prompt - I didn’t know if I was supposed to use If…else + another completely different paragraph of code (another If) OR just use If…else if. I solved it both ways but have just commented out one of the solutions.

Conditionals 2:

Conditionals 3:

Conditionals 4:

Thank you for your time!

Really happy to be here,
Rares
:slight_smile:

Welcome back @raresd!

Congratulations! Great job :medal_sports:

Here are my comments:

  • Task 1: Correct :white_check_mark: Something like your commented out code was requested. It’s just a basic test to see if you understand nested if..else statements. (That you obviously do :slightly_smiling_face:)
  • Task 2: Nearly correct :warning: The first conditional should have < and > because 0 and 100 are valid scores. Simplification: Testing a boolean for true is redundant. You can just write if (machineActive) for the same effect.
  • Task 3: Correct :white_check_mark: You could also put the first condition into a default option at the end of the switch statement.
  • Task 4: Correct :white_check_mark: Simplification: Put pwdResult = at the start of the line to not having to repeat it.
    pwdResult = (pwd === 'cheese') ? "..." : "...";
    

On a general note: When using CodePen you should put your CSS and JS in there respective panes instead of using the given <style> and <script> tags. It improves readability.

I hope that helps :smiley:

Happy coding,
Michael

2 Likes

@mikoMK thank you for all the tips and for taking the time to evaluate my tasks!:slight_smile:

The simplification you suggested for Task 4 was really helpful. Did not cross my mind that I could do that, so it’s nice that I can get this piece of info under my belt.

Also I’ll definitely include the JS in the appropriate pane in further pens!:stuck_out_tongue:

Have an awesome day,
Rares
:large_orange_diamond:

2 Likes

I’m glad you learned something new :slightly_smiling_face:
The reason this works is because the ternary has a higher precedence (priority) than the assignment. If you want to scare yourself have a look at the table in the link. :grin:
We there see that the equality has 9, ternary has 3 and assignment has 2.

1 Like

Heheh. I did get to take a peek at operator precedence in a previous lesson (I’m doing The Odin Project) but it’s definitely a lot to take in. I’m guessing I’ll get more and more used to them as I actually put them into practice. :smiley:

1 Like

I have never heard of it. Thanks for mentioning it. Looks interesting and will have a look. :blush:

Exactly! You will probably never encounter most of the possible combinations of this table. Others just feel natural like new or + having a higher precedence than =. Personally, I never went to this table and tried to memorize it. (and I definitely couldn’t rewrite it off the top of my head) :sweat_smile:

1 Like