Curriculum

Curriculum

Watch a Variable Change

Scenario

A study room begins with two available seats.

  1. 1Set freeSeats to 2
  2. 2One student books a seat
  3. 3That student cancels

Try it yourself

Predict the value of freeSeats after each event.

Reveal the explanation
  1. Set freeSeats to 2

    The current value is 2.

  2. One student books a seat

    Subtract one. The current value is 1.

  3. That student cancels

    Add one. The current value is 2.

A trace records the value after each update. Starting at 2, booking twice would leave 0.

Your turn

Start with two seats. Book one, book one more, then cancel one. Record the value after each event.

Common mistake Reading the old value after an assignment.

Check your work

The trace shows 2, 1, 0, 1 in that order.