let sale = true;
if (sale){
console.log(‘Time To Buy!’);
}
Am I doing something wrong here or is it a site issue.
let sale = true;
if (sale){
console.log(‘Time To Buy!’);
}
Am I doing something wrong here or is it a site issue.
NaN works as false with me??
> NaN && true
<- NaN
AND short-circuits on falsy, so that means NaN
is also falsy.
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
Thank you mtf, NaN, I believe should as part of false statement. Correct?
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.
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:
There may be more that I missed, but this should be a fairly comprehensive list.
I hope this clears it up.
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