Boolean Expressions Lesson

A boolean expression is any expression that evaluates to true or false. Comparisons such as score > 50, health <= 0, and name === "Ava" are boolean expressions because the answer is either yes or no. Boolean expressions can be combined with && for and, || for or, and ! for not. These operators let a program describe more realistic rules than a single comparison can handle.

Code Runner Challenge

Boolean Expressions Lesson

View IPYNB Source
%%js

// CODE_RUNNER: Boolean Expressions Lesson

let score = 85;
let lives = 2;
let levelComplete = true;

let canAdvance = score >= 80 && lives > 0 && levelComplete;

console.log("Can advance: " + canAdvance);
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...
The rule below requires a strong score, at least one life, and a completed level. The final variable stores the result of the whole expression.