Assessment wanted for Conditional exercise

Hello! Very new to all of this, and I would appreciate some feedback on the conditionals exercises! (https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Test_your_skills:_Conditionals)
2 - https://codepen.io/meridethmurdock/pen/wvGGXxX
3 - https://codepen.io/meridethmurdock/pen/mdPPKgp
4 - https://codepen.io/meridethmurdock/pen/zYqqLOq

Hi @merideth.murdock, and welcome to the commmunity!

I’m more than happy to give you some feedback on your code. If you have any more questions, don’t hesitate to ask.

For the second exercise, you are on the right track, but there is a bit of clean up to do so we can get this working.

First of all, you need to update instances of if else to else if for it to work. JavaScript is pretty strict about syntax being correct.

Second, in the conditions, where you’ve used =, for example in score = 100, you need to use === instead. = is the assignment operator, which you use to assign a new value to a variable. === is the strict equality operator, which you need in this case, as you are testing whether a variable value is equal to something. This is a very common mistake, so don’t worry about it; I still do that sometimes.

For the third exercise, you’ve basically got this right, except for the same comment about operators as above.

And also you have the conditions inside quotes, which means they are not being evaluated as math expressions, but as strings, which breaks the switch statement.

Lastly, you need to change the opening switch line to switch (true) — I’ve tried to explain why here: Assessment wanted Conditionals 3

One thing that might help is for you to space out your code a bit more, so it is easier to see what is going on. see our answer for example https://github.com/mdn/learning-area/blob/master/javascript/building-blocks/tasks/conditionals/marking.md#task-3

@merideth.murdock oh, and for assessment 4, you are on the right track, but the syntax is a little bit confused. Have a look at our answer for some guidance on this one: https://github.com/mdn/learning-area/blob/master/javascript/building-blocks/tasks/conditionals/marking.md#task-4

But overall, your answers are all good attempts, and were very close. I’m impressed, especially given that you are so new to this.

Oh my god did I really type “if else”? hahaha what a silly mistake. No wonder it didn’t run correctly. Thank you so much for your reply! This helped a lot! :slight_smile: I did have one question, in the fourth exercise where I used “!machineActive”, is that correct syntax? I see in the solution you linked, the conditional is just run if true, and then the “else” is the machine is off, but would my version work? It was kind of a shot in the dark, as the machineActive value is set to true, I figured I would have to state what happens if it’s set to false, but I understand why that isn’t needed.

@merideth.murdock No worries at all — we all make these mistakes from time to time, and there is so much syntax to learn.

To answer your question — yes, !machineActive is valid syntax — it basically inverts the test so that it is testing for the machineActive variable beingfalse rather than true.

You can test this in your browser’s developer tools console. Open your console, then try entering the following lines one by one

let machineActive = true
machineActive
!machineActive