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

create an if statement. Provide the if statement a condition of sale . Inside the code block of the if statement, console.log() the string 'Time to buy!' .

if (true) {
console.log(‘Time to buy!’);
// Prints “Time to buy!”

if (sale = true) {
console.log(‘Time to buy!’);
// Prints “Time to buy!”

I can not go to task 3?

1 Like

Recall that = is the assignment operator and is not used for comparison. Instead we use, === to test identity.

sale [isIdenticalTo] true

However, it is not necessary to compare to a boolean. We can simply test for truthiness

sale = ""
if (sale) {
} else {
    console.log('Not true')

everytime i in put if (true) {
} the console log part all turns blue instead of the normal color, what am i doing wrong?

Can someone explain this please?
The user above me asked a question but no response. I have the same issue:

"I was expecting to put an argument in the if statement.
eg. if(sale = true){


not just (if sale){}

Where did I miss this crucial step?

I went elsewhere to find that a varialbe not assigned a value is a primitive boolean ‘0’, while a variable assigned a value is a primitive boolean ‘1’

1 Like

When we compare a value to a boolean literal, true and get a true result, that means the value is itself a boolean literal. There is no need to ever compare to true. Just test the truthiness.

false => 0, '', "", null, undefined
true  => 1, ' ', " ", NaN, {}, []

Everything on the right of, => can be coerced to the primitive on the left.

A comparison which uses equality and inequality operators always evaluates to a booleean primitive. Now we mentioned earlier that when a value is already a boolean primitive we can test it with if and while directly.

if (sale)

is the same as,

if (true)

but for one thing: sale is a state whereas true is a definite literal. The former can change, while the latter is immutable.


Does this mean that if statements default to true?


I think you are right.

If someone can explain if the “if” statement is true by default ?

if (condition) {
  // condition must evaluate to `true` (must be truthy)
  // to be able to enter this branch


I do not believe you missed any step. I think you may have just overthought the exercise.

Originally in the exercise, they ask you to create a variable for sale and set it’s value to true.

let sale = true;

Now the variable sale is equaled to true. So if you where to type console.log(sale); this would print true.

To answer your question "what condition is necessary to show that ‘sale’ is ‘true’?
Simply put, the value that you set to the variable sale creates the condition, which in this case equals true

Your variable can have many values or conditions based on what you decide it should be.
let sale = true; // this sets the condition to true.
let sale = false; // this sets the condition to false.
let sale = 10; //this sets the condition to the number 10
let sale = ‘Hello World’; // this sets the condition to a string ‘Hello World’

Now you can check to see if sale is equaled to true by writing an if statement.
if (sale === 10){

console.log(‘This statement is true’)}

else if(sale === ‘Hello World’){

console.log(‘This statement is true’)}


console.log(‘This statement is false’)};

Hope this helps!


Just as you can say

if (sale === true) {
console.log("Time to buy!");


if (true){
console.log(“Time to buy!”);

Can you also say something like,

if (false){
 console.log("Time to buy!")

There by testing for falsiness rather than truthiness?

The code in the block will not run. IF can only let a truthy value into the code block. To test for falsiness we would use the NOT operator…

if (! sale) {
    // sale in this case is falsy

In other words, the only values that will meet the conditional are,

  • undefined
  • null
  • NaN
  • “”
  • 0
  • BigInt 0n
  • false

To check if a value is truthy (it evaluates to true) we can write it like this:

if (value) {
  // Code will get executed if value is truthy

Falsy values

  • An empty string ("", '')
  • The boolean false
  • null
  • undefined
  • The number 0
  • NaN

Truthy values => Everything that is not falsy (1, "Hello", true, etc.)

Sometimes, we want to check if a value is falsy (evaluates to false). To do this, we can use the NOT operator:

if (!value) {
  // Code will get executed if value is falsy

Finally, we can check if a value is equal to a specific value. E.g. if a variable is equal to the numeric value 2

if (value === 2) {
  // Code will get executed if value is equal to the numeric value 2

=== : The strict equality comparison operator will check if the value on the left-hand side is equal to the value on the right-hand side and if the value on the left-hand side is the same data type as the value on the right-hand side

== : The abstract equality comparison operator will only check if the value on the left-hand side is equal to the value on the right-hand side. It will not check for equal data types meaning "2" == 2 evaluates to true


Porque teve que colocar venda como falso? numa condição verdade nao é sempre primeiro?(fazendo uma comparação ao excel) ou no JS nao funciona assim? na verdade so quero entender de verdade o porque, li a faq mas nao ficou muito claro talvez por conta da traducao q uso automatico mas enfim devo entender nos proximos exe.

No exercício eles pedem para você colocar sale = false; justamente pra você ver que o if não vai imprimir/rodar, já que a variável sale, agora é falsa de acordo com a nossa declaração;

Ola Tassia! obrigada por responder. sim, depois que fiz a pergunta voltei ao exercício reli algumas coisas forum, faq fiz alguns teste faço ainda algumas confusões mas tá fluindo rs. vlw

1 Like

I gotta be honest here… so far, I’ve loved Codecademy. This lesson is just pure garbage though. Their whole process of force feeding and handholding without alternative examples as to why it works the way it does is pretty darn bad. I get what they think they’re doing… but it’s unproductive for large chunks of time for someone who is learning. Pretty glad I’m just sticking to the free stuff.

let sale = true;

if(sale === true){

console.log(‘Time to buy!’)



let sale = true;

if (sale) {

console.log(‘Time to buy!’);


1 Like

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