If... else statement

Please can someone explain to me why the statements are contradicting? let sale=true (means sale is true) but then we put another line sale being false? I am slightly confused, tried to run the code as if let sale = false, sale = true, that case it still runs the case as "Time to buy" even though variable says that sale is false? (The given code is below)

let sale = true;
sale = false;

if(sale) {

  console.log('Time to buy!');

} else {

  console.log ('Time to wait for a sale.')


I ran your code here:


and the else clause runs, as expected.

Thanks a lot for your reply.

That code was given by the Codecademy, which is completely correct. However my question is if I run the code below, why the statement is not ‘Time to wait for a sale’ ? (meaning if sale is false then statement should be “time to buy” but the sale is = true so the code should give me ‘time to wait for a sale.’)

let sale = false;
sale = true;

if (sale) {
console.log (‘Time to buy!’)
} else {
console.log (‘Time to wait for a sale.’)

when the if condition is true, that clause runs. Given sales is true, we should see Time to buy, which we do

the else clause runs when the if condition is/evaluates to false.

Got it! Thank you again :slight_smile: