- Understand the concept of an event listener
- Attach an event listener to a button
- Continue building a developers mindset by breaking code and being ok with it!
Imagine that you’ve just ordered food from GrubHub and are waiting for it to arrive. When the doorbell rings, you’ll stand up from the couch, walk over to the door, open it, and take your food. Guess what? You programmed yourself with an event listener.
Let’s look at this example of an event listener and talk through the pieces:
Applying What We’ve Learned
Back in your own Puppy Facts CodePen, add a button in the HTML.
If you complete that with extra time, change the text in the
p tags so that when the button is clicked, the facts match your new topic!
🌶Click here for a Spicy Challenge🌶
Wouldn't it be nice if the user could toggle back and forth between Puppy Facts and your other facts? Add another button, then implement the code to make this happen.