12. The logical operator OR


#1


Replace this line with your code.


#2

What is wrong?

var tired = true;
var bored = false;

var nap = function() {
if(tired && bored){
console.log("Bla");
}
else
if(!(tired || bored)) {
console.log("Bla bla");
}
else {
console.log("Bla bla bla");
}

};


#3

@mezzosonja, What do you want to do?

If function nap compare two variables, it's should be:

var tired = true;
var bored = false;

var nap = function(x, y) {
   if(x && y){ 
      console.log("Bla");
   } else if( !(x || y) ) {
      console.log("Bla bla");
   } else {
      console.log("Bla bla bla");
   }
};

// important to call defined function:
nap(tired, bored); // "Bla bla bla"

I defined function nap with 2 parameters x and y and implemented your logic using this parameters. When I called this function, I put variables tired and bored as arguments of function nap(x, y).

Now you can put any arguments (but only two) and see result.


#4

Create two variables, tired and bored, and set one equal to true and the other equal to false. (It doesn't matter which is which.) Inside the nap function, create an if statement that returns true if either tired or bored (or both!) are true, and false otherwise.

But, with or without parameters I get this notice: "Oops, try again. It looks like your function doesn't return false when tired and bored are both false."


#5

Sorry, I didn't check instruction to the lesson. You need to use operator || and your function has to return a boolean value:

// Declare your variables here!
var tired = true,
    bored = false;

var nap = function() {
  // Add your if/else statement here!\
  if(tired || bored) return true;
  else return false;
};

nap();

As a result when tired and bored are both false function returns false.


#6

thank you very much :slight_smile:


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.