LESSON 10

Conditions

Learning objective: Understand how conditions control program flow.

Understand

Conditions let programs make choices.

A condition is any expression that evaluates to true or false. Based on it, your code can take different paths. Conditions are the gateway to if statements and loops.

Analogy: A condition is like a fork in the road: the answer decides which way you go.

See It in Action

A condition used in a check:

let temp = 30;
let hot = temp > 25;
console.log(hot); // true
How it works: The comparison temp > 25 is the condition; it produces a boolean that decides what happens next.

Try It Yourself

  1. Write a condition comparing two numbers.
  2. Store the result in a variable.
  3. Log whether it is true or false.

Quick Quiz

What does a condition evaluate to?

Challenge

Write three conditions about a value and log each result.

Success condition: Each condition logs a correct true or false.