Logical operator "NOT" in 13 (More on Control Flow)


#1

I'm confused with this exercise.
We're told to make the function "happy" true when the variable "programming" is (declared as) false. The solution aimed at here, i.e. negating the variable "programming" in the if-condition (so that it becomes true), followed by "return true", is in conflict with the briefing, I think:

Declare a variable called programming and set it to false. Then, write an if/else statement inside happy so that happy returns true if programming is false and false otherwise.

Should it not be:

Declare a variable called programming and set it to false. Then, write an if/else statement inside happy so that happy returns true if programming is TRUE and false otherwise.


#2

@netrunner43800

Yes it is completely LOGICAL.
If programming is false, then we return false. If it is true then we print true.


#3

Thank you for your answer.
If I understand your feedback correctly, we end up with this (which is marked as correct in the browser). It doesn't involve any negation, however.

var programming = false;

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

};


#4

@netrunner43800

Exactly. This should work. :slight_smile:


#5

It does, but it is not what is asked for in the briefing


#6

i agree @netrunner43800, something isn't right about how this is worded. the error message i just got is classic: "Oops, try again. It looks like your happy function returns true instead of true when programming is true." WTF?


#7

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