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