What condition is necessary to show that `sale` is `true`?

let sale = true;
if (sale){
console.log(‘Time To Buy!’);
}

Am I doing something wrong here or is it a site issue.

2 Likes

NaN works as false with me??

 > NaN && true
<- NaN

AND short-circuits on falsy, so that means NaN is also falsy.

1 Like

Thank you! I was getting hung up on this point also, that we weren’t evaluating anything in the parenthesis, but this makes perfect sense after reading this :pray:

1 Like

Thank you mtf, NaN, I believe should as part of false statement. Correct?

1 Like

Correct. Good catch. It only took 32 months for someone to spot that.

NaN && true  =>  NaN

which indicates a short-circuit; therefore, falsy.

Too late to edit the post, but future readers will be set right if they get down to this one.

1 Like

For all of you that struggle with the 2nd step of the lesson, the console.log ‘Time to buy!’ you need to use the ‘SINGLE QUOTE’ for the string and not ``

This is what I think about If statements
let sale = true;
if (sale) {
console.log(‘Time to buy!’);
}

Let sale = true;
sale = false
if (sale) {
console.log(‘Time to buy!’);
}

Totally agree!
I think that the exercise steps are a bit confusing and “if” is not explained clearly. Forum replies helped a lot though!

In the code
If ( sale ) {
console.log(“example”);
};

The code checks if the variable sale exists and then runs the code. The exception is when the variable’s value is considered “false”.
Situations where the variable is considered false are:

  • When the value is equal to 0.
  • When the value is set to false.
  • When the value is undefined (No value has been assigned yet).
  • When the value is set to null.

There may be more that I missed, but this should be a fairly comprehensive list.
I hope this clears it up.

2 Likes

let sale = true;

if (sale) {
console.log(‘Time to buy!’);
}

This is what worked for me, agree the instructions are unclear at 2.

// The code that worked in practice 
let sale = true;
if (sale === true) { 
  console.log('Time to buy!');
}

Thank you for introducing the ‘!’ sign.
On Codecademy since a few days, I always scroll in the forum after every lesson, it makes learning much more efficient.
So I tried to implement the ‘!’ sign in the exercise:

let sale = true;
// sale = false; texted out on purpose
if (!sale) {
console.log(‘Not time to buy!’);
}
else {
console.log(‘Time to buy now!’);
}

Would it be a bad habit to use this kind of formulation where I would execute the action linked to truth in the else part of the conditional statement ? Could it be confusing and should it be avoided ? Thanks