Lesson 5
Lesson 5 of 16
Boolean Operators
Lesson Progress: 0%
Code Example
raining = true;
warm = false;
console.log(raining && warm); // false
// Do you have a ticket AND is the movie starting?
let hasTicket = true;
let movieStarting = true;
console.log(hasTicket && movieStarting); // true
// Is the game over AND did you get a high score?
let gameOver = true;
let highScore = false;
console.log(gameOver && highScore); // falseInstructions
▼ ← Click the triangle to hide or reveal instructions.JavaScript Code Editor
Task Incomplete
Editor Input:
Editor Output:
&& symbol is like a checklist where every single box must be checked "Yes."false, the computer gives up and says "false."true when both sides match perfectly.Code Example
cold = true;
snowing = false;
console.log(raining || warm); // true
// Do you have a coupon OR is it a free-cookie day?
let hasCoupon = true;
let freeDay = false;
console.log(hasCoupon || freeDay); // true
// Is it the weekend OR are you on summer break?
let isWeekend = false;
let isSummer = false;
console.log(isWeekend || isSummer); // falseInstructions
▼ ← Click the triangle to hide or reveal instructions.JavaScript Code Editor
Task Incomplete
Editor Input:
Editor Output:
|| symbol is like a "One or the Other" rule; the computer is happy if just one side is true.false if both sides are wrong at the same time, like having no weekend and no summer break.Code Example
cold = true;
snowing = false;
console.log(!cold); // false
console.log(!snowing); //true
// If the game is NOT over, keep playing!
let gameOver = false;
console.log(!gameOver); // true
// If the light is NOT on, it must be dark.
let lightOn = true;
console.log(!lightOn); // falseInstructions
▼ ← Click the triangle to hide or reveal instructions.JavaScript Code Editor
Task Incomplete
Editor Input:
Editor Output:
! symbol is like a "Reverse Button" that flips a value to its exact opposite.false into true and turns true into false.