10. Overwiev




Should not this example be like this below? I think that in the example the sentences “Let’s see if we can change your mind.” and “You only like one but not the other? We’ll work on it.” are in the wrong places

// Complete lines 3 and 4!

var iLoveJavaScript = true;
var iLoveLearning = true;

if(iLoveJavaScript && iLoveLearning) {
  // if iLoveJavaScript AND iLoveLearning:
  console.log("Awesome! Let's keep learning!");
} else if(!(iLoveJavaScript || iLoveLearning)) {
  // if NOT iLoveJavaScript OR iLoveLearning:
  console.log("You only like one but not the other? We'll work on it.");
} else {
  console.log("Let's see if we can change your mind.");


Hi maria,

I could be wrong, but if I understand correctly, I believe the example as written is correct. Here’s why:

Both if and else if statements generally run if true. The first one is easy enough to understand at first glance: if both vars are true, the if statement will run.

Next line is a bit trickier however. In order to run, the condition must be false. Why? Because there is a ! in front of it; !false = true.

Perhaps important to understand in this case is "how does ‘or’ work?’'
If you look at the link you will see that if the 1st var, 2nd var, or both vars are true it will return true. It will only return false if both vars are false. This table is a quick way to check if the statement will be true or false.

In other words, the only way the else if can run is if iLoveJavaScript and iLoveLearning are both false.

Since the if statement addresses people who love both JavaScript and learning, and as we’ve just established, else if addresses those who hate both Javascript and learning, that must mean that else will only run if the user loves one but not the other.

Does that make sense?

In this sense, I agree that the example could be improved for clarity if the relevant comment read “if NEITHER iLoveJavaScript NOR iLoveLearning”, especially considering ||'s evaluation process has not yet been explained.