Using the let keyword, declare a variable named sale and assign the value of true to it.
let sale = true;
Create an if statement and provide the if statement a condition of sale.
if (sale) {
}
Inside the code block of the if statement, console.log() the string 'Time to buy!'.
if (sale) {
console.log('Time to buy!')
}
The if statement ran. Now below the sale variable declaration, but before the if statement, reassign sale to false. Run your code...(will result in error).
let sale = true;
let sale = false;
if (sale) {
console.log('Time to buy');
}
Add an else statement to the existing if statement. Inside the code block of the else statement, console.log() the string 'Time to wait for a sale.'
let sale = true;
sale = false;
if(sale) {
condole.log('Time to buy!');
} else {
console.log('Time to wait for a sale.')
}
Comparison Operators
Using let, create a variable named hungerLvl and set it equal to 7.
let hungerLvl = 7;
Write an if...else statement using a comparison operator. The condition should check if hungerLvl is greater than 7. If true, console.log() 'Time to eat!'. Otherwise, console.log() 'We can eat later!'.
let hungerLvl = 7;
if (hungerLvl > 7) {
console.log('Time to eat!');
} else {
console.log('We can eat later!);
};
Logical Operators