"not" logical operator


#1

Here is my code:

var programming = false;

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

Here is my warning message: Oops, try again.
It looks like your happy function returns false instead of false when programming is false


#2

Most operators are in the order in which you would speak them so here it is:not eqal != instead of equal not =!
Also else doesn't need a condition so this line makes no sense: (programming = !false);

PS: =! is in this case not syntactically wrong because here it the not would operator on the true changing it's value to false, but then the = would be an assignment operator and no longer compare these values. Which makes no sense you do want to check if it is not equal and not assign a !true to programming, do you?


#3

this looks risky, take a look at this line of code:

console.log(!false)

it will print true. What is happening? ! will reverse it. So in this condition:

if (programming = !true)

you assign the Boolean false (!true) to programming. Then the if statement will evaluate to false, so else will execute.

I think what you are looking for, is the not equal operator:

if (programming != true)

which is very different. Also, this bit:

(programming = !false);

doesn't make any sense, why it is inside your else? As far as i can tell, it serves no purpose, and you don't need to condition checking at else (since it is everything else)


#4

This has helped but I still can't seem to pass. even after some googling.

Here is my code:
// Declare your variables here!
var programming = false;

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

} else {
return false;
}
};

Now I get this:
ReferenceError: invalid assignment left-hand side


#5

NO WORRIES MANAGED TO DO IT !!

It was a Brackets issue:

if ( ! (programming) ){
return true;


#6

why are you not using !=? You are making it yourself rather complicated


#7

Im trying not to. :slight_smile:

I find coding very difficult.