Skip to content
Exit presentation

Programming Proper I

A box you can change, and a box you cannot

The bus has 32 seats, and that number does not change. The number of people in the queue outside the gate changes.

Loading lab…

Two boxes made: waiting = 18, seats = 32.
Step 1 of 4
  1. Two boxes made: waiting = 18, seats = 32.
  2. waiting can refill: waiting = 24.
  3. seats cannot refill. 40 is refused.
  4. seats still holds 32. The run stops here.

The rule

let can be given a new value later. const cannot. The machine stops the run if you try.

let waiting = 18;

const seats = 32;

In code, = means store, not equals. The box on the left receives the value on the right.

The two words that make a box, and what each promises
WrittenCan a later line replace it?
let waiting = 18;Yes
const seats = 32;No

const does not mean secret or important. It means the box cannot be refilled after it is made. So const suits the seats, and let suits the queue.

waiting = waiting + 6; looks odd. It is not a Maths equation. The right side is worked out first. With waiting at 18, that gives 18 + 6 = 24. Then 24 is stored in waiting.

Try to change a const and the run stops. The machine names the box and says why:

seats was made with const, so it cannot change. Use let if it should.

Jump to lesson

This track

  1. 0 Start here
  2. 1 The same program, typed instead of dragged
  3. 2 A box you can change, and a box you cannot
  4. 3 Four kinds of value, and why the quotes matter
  5. 4 What the signs do, and the one that does two jobs
  6. 5 A fork in the line
  7. 6 A loop that runs until something stops it
  8. 7 Once for each thing you have
  9. 8 What the message says, and what it does not
  10. 9 The big picture
  11. 10 Track quiz

Other tracks