Buttons and Events

Recap

Housekeeping


1. Spoiler Demo

Materials

2. Introduction to Events

Materials

Demo: Triggering functions with a button

  • Starter code: Spoilers from Function Refactor session

Breakout Activity

In pairs: Try to repeat what Tony did in his demo

  1. Pick one of the functions from today's spoilers
  2. Goal: refactor the code so that the prompt(s) start on a button click
  3. Create a button element
  4. Assign that element to a variable with document.querySelector()
  5. Wrap the prompt code into a clickHandler function.
  6. Add that function as a button click event using button.addEventListener()

3. More events and elements


Lab Time

Main Room: Dark Mode Toggle


Prep