I am working on a JavaScript exercise on an interactive website, and I just really need some assistance in understanding the logic behind this...
The exercise asks that you define a variable programming, and set it equal to false.
var programming = false;
Then, if programming equals false, a function, happy
is to return true.
programming
has already been set to false, so my first thought was to just write:
if (programming) {
// this
I made the mistake of not using the ! operator, which is what they were requesting, so I then tried to write:
if (!!programming) {
// this
To me, this says: not not false
which I thought would cancel out and equal false
But I get the following error:
Oops, try again. It looks like your happy function returns true instead of false when programming is true
this works:
if (!programming) {
// this
I'm just not understanding why (!programming) evaluates to false, when I believe this is basically saying: (!false)
Please help me understand the error of my ways. Thank you.
For a reference, here is my full code:
var programming = false;
var happy = function() {
if (!programming) {
return true;
} else {
return false;
};
};
Edit:
I've found the solution. zystvan explains it on this post: https://discuss.codecademy.com/t/why-is-this/42458