# Assessment for conditional 2 test

**URL:** <https://discourse.mozilla.org/t/assessment-for-conditional-2-test/71778>\
**Category:** Learn\
**Created:** [December 7, 2020, 8:51am UTC](https://discourse.mozilla.org/t/assessment-for-conditional-2-test/71778 "2020-12-07T08:51:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dev2](https://avatars.discourse-cdn.com/v4/letter/d/7bcc69/32.png) [@Dev2](https://discourse.mozilla.org/u/Dev2)\
**Post date:** [December 7, 2020, 8:51am UTC](https://discourse.mozilla.org/t/assessment-for-conditional-2-test/71778/1 "2020-12-07T08:51:13Z")

</div>

Hello everyone.  
I have written the solution for the conditional 2 test. It’s working but I really appreciate an assessment. I’m not sure I’ve done everything as required but I figured out a way to make it work.  
Look forward to hearing from you.  
My code:  
[https://codepen.io/mahmoud-fed/pen/MWjegJO](https://codepen.io/mahmoud-fed/pen/MWjegJO)

instructions are on the following page:

[Conditionals 2](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Test_your_skills:_Conditionals)

---

<div class="post-metadata">

**Author:** ![justsomeone](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/justsomeone/32/67787_2.png) [@justsomeone](https://discourse.mozilla.org/u/justsomeone)\
**Post date:** [December 7, 2020, 2:08pm UTC](https://discourse.mozilla.org/t/assessment-for-conditional-2-test/71778/2 "2020-12-07T14:08:05Z")

</div>

elslamo alikom @Dev2

you doing great just some tips and advice

```auto
if(!(machineActive==true)){
response = "Turn machine on" 
}

```

when compare it recommened to use === not just == why?  
cause === compare the variable and check if they are from same type but == only compare the values  
for example  
let x =5 let y =“5”  
if we use x==y that would lead to true but if we use x===y that would be false  
and we should compare with the same type cause the other one could lead to bug that really hard to find later in big projects

and for this

```auto
if(machineActive=true)  

```

first you should use else not if and the condition is always true cause that would set machineActive to true which will make it always true  
in js any true or non 0 or not null is true

hope that help and have a nice day 🙂

---

<div class="post-metadata">

**Author:** ![Dev2](https://avatars.discourse-cdn.com/v4/letter/d/7bcc69/32.png) [@Dev2](https://discourse.mozilla.org/u/Dev2)\
**Post date:** [December 7, 2020, 7:58pm UTC](https://discourse.mozilla.org/t/assessment-for-conditional-2-test/71778/3 "2020-12-07T19:58:14Z")

</div>

thank you @justsomeone for your practical advice. In fact, I tried === first but the code didn’t work. Then it worked when I used two equal signs ==. I don’t know why.

---

<div class="post-metadata">

**Author:** ![justsomeone](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/justsomeone/32/67787_2.png) [@justsomeone](https://discourse.mozilla.org/u/justsomeone)\
**Post date:** [December 7, 2020, 8:29pm UTC](https://discourse.mozilla.org/t/assessment-for-conditional-2-test/71778/4 "2020-12-07T20:29:16Z")

</div>

you very welcome but not sure what could be the cause of that 🙂

---

<div class="post-metadata">

**Author:** ![Chrysaoros](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@Chrysaoros](https://discourse.mozilla.org/u/Chrysaoros)\
**Post date:** [December 9, 2020, 3:00pm UTC](https://discourse.mozilla.org/t/assessment-for-conditional-2-test/71778/5 "2020-12-09T15:00:04Z")

</div>

I’ve taken a look at your code and i’d say it needs a bit of fixing.  
First off, you’ve used two different if statements for (machine === false) and (machine === true) when in fact, the task was to make an if statement for machine on/off (true/false) and then NEST if…else if… else statements inside the (machine === true) block to check the score values.

**So not this:**

```
// first if statement
if (machine === false) {...}

// second if statement (nested)
if (machine === true) {
  ...
  else if (score...) {
  ...
  else {
    ...
  }
}

```

**But this:**

```
// one if statement - machine is on
if (machine === true) {
  ...
  // check score
  if (score...) {
    ...
    // check other score
    else if (score...) {...}
    // if not any of the scores above, this score 
    else {...}
  // machine is off
  else {...}

```

The last else {} (outer) block runs ONLY on the condition that machine === false so it is not necessary to explicitly state this since your first condition was that the machine === true.

**Secondly, it is not necessary to explicitly state this:**

(machine === true) or (machine === false)  
All of the values in JavaScript evaluate to a “truthy” and “falsy” value - this means that JavaScript itself forces values in the background to “true” or “false” for the purposes of conditional checks.  
There are 6 values in JavaScript that evaluate to a “falsy” value:

```
false
0
""
NaN
null
undefined

```

This means that your FIRST if statement could’ve been written like this:

```
if (machine) {
...
} else {
...
}

```

It means “Do this if machine === true, else do this if machine === false”.

Thirdly, you don’t check whether score is in between numbers since you’re using OR operator (||). You should instead use AND (&&). Here’s what i mean:

`(score ===0 || score <=19)`

OR operator only cares about whether ONE of these operands is TRUE. AND operator has to have ALL operands TRUE in order to have the whole expression evaluate to TRUE. For example:

`(score >=0 || score <=19)`

score = 5 ==\> TRUE  
score = 20 ==\> TRUE  
score = -1 ==\> TRUE  
OR operator DOES NOT check in between values. It only cares whether one of these is TRUE.

If you’ve written this with an AND operator:

`(score >=0 && score <=19)`

ALL conditions would’ve been checked.  
score = -1 ==\> FALSE  
score = 5 ==\> TRUE  
score = 20 ==\> FALSE

---

<div class="post-metadata">

**Author:** ![Dev2](https://avatars.discourse-cdn.com/v4/letter/d/7bcc69/32.png) [@Dev2](https://discourse.mozilla.org/u/Dev2)\
**Post date:** [December 9, 2020, 5:27pm UTC](https://discourse.mozilla.org/t/assessment-for-conditional-2-test/71778/6 "2020-12-09T17:27:14Z")

</div>

Thank you very much @Chrysaoros for this detailed explanation. this is very helpful.
