Command Palette

Search for a command to run...

Hectal
Phase 9: Events
JavaScript · Exercise 2 of 6 PreviousNext
Beginner

Volume with the arrow keys

The volume in #volume starts at 5. Listen for keydown on document:

- ArrowUp adds 1, but never above 10.

- ArrowDown takes away 1, but never below 0.

- Any other key changes nothing.

Also call preventDefault() for the two arrow keys so the page doesn't scroll.

What Check tests

  1. ArrowUp adds one
  2. ArrowDown takes one away
  3. It never goes above 10
  4. It never goes below 0
  5. Other keys change nothing
  6. Arrow keys don't scroll the page

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.