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

You need to know that = (a single equals sign) is an assignment operator and literally assigns a value to a variable.
To check if a conditions is true for now use == (double equals).
if you had typed

if (sale == true) {

}

that kinda would have been logically correct. But doing if(sale) {…} is a SUPER common shorthand that will result in a valid output. And this will always check for the condition to evaluate to TRUE.
I hope this helps.

When using an if statement, the statement is being evaluated if it’s true. And because we set the sale variable (let sale= true), the statement will be evaluated as true. Once our if statement is evaluated as true, the code block containing the console.log will be executed.

If we set the sale variable to false (let sale = false), the if condition is evaluated to false and therefore the code block will not be executed. Hope this helps!

1 Like

I think that you are overly critical. The lesson is about 1 minutes and you are criticizing it like it is a morning of wasted time. Grow up!

The very first step was to assign the variable sale = true via…

let sale = true

Then you wrote the if statement with the argument of (sale).
The computer already knows sale = true so you dont need to write it in the if statement you just write the variable. You might as well be writing true in the eyes of the computer.

1 Like

In Philosophical logic, if you state a word or phrase the implication is that it is true.

A therefore B ( sale therefore true).

Stating A implies B like stating sale implies true.

Hope this helps as opposed to making it more confusing!

// STEP 1
let sale = true;
//STEP 2
if (sale) {
console.log('Time to buy!');
}

//STEP 3, code should look like this :

let sale = true;
sale = false;
if (sale) {
console.log('Time to buy!');
}

Do not get ahead of the lessons with what you are trying to do.

2 Likes

I was also confused because I thought about testing equality instead of thinking about the initial goal of the exercise, additionally, I believe that this overthinking happens because of the way that javascript treats ‘=’, it differs from what we’ve been taught as kids, where ‘=’ means equality, while in JS ‘=’ means ‘it becomes’. Thanks for highlighting this :slight_smile:

I love code academy really. I couldn’t have learnt it else where be it YouTube or Udemy. The video tutors just selling their lessons. I am glad that I paid everything in one go, got it cheaper as well as I m in love with coding so far. Btw its coming from a guy who had ZERO knowledge in coding. Its like a kid goes to Nursery school and then progress through step by step.

1 Like

Ok!

So am I right in assuming that “if (sale)” is the default for “if(sale == true)” and when writing a variable in this manner as a condition, it will always be true?

Thank you!

If the value for sale is truthy, control flow will be through the true branch of the if statement. Nothing is certain, that is why we need to test with a conditional.

2 Likes

Oh, so am I safe in assuming that if we DON’T write “let sale = true” as the variable at all in the program, then we DO have to declare the condition as “if(sale == true)”?

Please, if I understood correctly?

When the variable is explicitly set to true then it will pass the truthiness test, with no comparison necessary unless we want it to be specifically, true, and not just truthy. We would need to use strict equality, though, since with loose equality, true == 1 is true, but true === 1 is false.

I agree this was a somewhat poor introduction to the ‘If’ conditional.

But it’s not an introduction to ‘if’. That should have already been covered somewhere earlier. This is about truthy, aka, ‘truth value’ and how it behaves in any conditional, including, if.

Grade yourself, not the lesson, and park the griping. We’re here to learn, by whatever means necessary. That implies determination, commitment, investment, &c. Focus on that.

1 Like

im a bit confused. im stuck here, i dont see where in my instructions where it tells me to change the value of sale to false?

this is actually the first time "if’ or any other statements are brought up in these lessons prior to this we were understanding variables

if it has not come up previous to this lesson, which I have difficulty understanding why it would not, then we may take this opportunity to get firsthand experience with the construct.

The key word applies to an expression that may be truthy or not in its evaluation. The code block immediately following the condition may only be entered when the evaluation outcome is truthy.

if (condition) {
   // condition must evaluate to truthy
}

A condition may be a comparison or a state. What the expression is matters little, they all get evaluated before flow continues either into the code block or around it.

1 Like

let sale = true;
console.log(‘Time to buy’);
with the condition statement:
if (true) {
console.log(‘Time to buy’);
}
both printed same outputs!

The boolean true is a fixed state. if (true) will always lead to the first branch of the statement. sale on the other had is declared with let so can have a change of state.

sale = true
if (sale) {

}
sale = false
if (sale) {
  // does not enter this branch
} else {
  // enters this branch instead
}

Bottom line, it is never recommended to write true in an if condition. It is the same as just executing the same statement (the true clause) every time.

1 Like

because you’ve already decided sale is true when inputing sale = true