Logical operators!


#1

I get an error msg telling me that I am returning true when Programming is true. It looks to me that it should be the opposite. programming=false and so running programming through happy func should yield false. So I would return true. But no....
My question is with the logic. And, I guess, the wording of the assignment is throwing me off.
Thanks

// Declare your variables here!
var programming=false;

var happy = function() {
  // Add your if/else statement here!
  if (programming){
      return true;
      }else {
          return false;
       }
};

#2

Even though you declared your variable programming = false, you can put an expression that evaluates to true (using !=) in your if() statement.

you should write it like this:

if(programming != true) //meaning, your programming is equal to false.
{
return true; //your programming is equal to false so it will return true base on the instruction
}

#3

Gracie,
Thanks for your response, but I have a question on the logic. I know that if(programming) would normally return as true but before the function I set var programming = false. Does the false value carry into the function? If so than !programming would equal true in this case.
Or is (variable) always true because that is just javascript for a boolean value.
Thanks.


#4

Your logical error was that you forgot to type the logical operator not before programming. See below:

var programming=false;

var happy = function() {
if (!programming){
return true;
}else {
return false;
}
};

happy();