Practice and reinforce the concepts from Lesson 10
In this activity, you will:
addEventListener() method⏱️ Estimated Time: 45-60 minutes total
⚠️ Warning DO NOT DELETE the existing files in the template:
- Package files
- Any other files you didn't create
ONLY EDIT the necessary files.
In each exercise below, click the Stackblitz link and familiarize yourself with the interface.
⏱️ Time: 15 minutes
stackblitz-starters-pwtgepdbFollow these steps:
button and select the button element using DOM.addEventListener() method to add a click event to the button:
💡 Tip Use this syntax:
button.addEventListener("click", () => { alert("I love JavaScript!"); });
Expected Results:

When you click the button:

💡 Tip Quick Reference:
document.querySelector('.className') or document.querySelector('#id')() => { /*statement*/ }⏱️ Time: 15 minutes
stackblitz-starters-3t2zje9rGoal: Create text that turns red when you hover over it
Follow these steps:
Add this paragraph element to your index.html file:
<p class="m-5 p-2">I love JavaScript</p>
In your JavaScript file:
text and select the paragraph elementmouseover event listener with an arrow functionmouseout event listener with an arrow function💡 Tip Helpful Methods:
text.classList.add("text-danger")text.classList.remove("text-danger")Expected Results:
Normal state:

When hovering:

⏱️ Time: 15 minutes
stackblitz-starters-wgitmbs8Goal: Create a key press detector that alerts which key was pressed
Follow these steps:
document for keydown eventsevent parameterevent.key💡 Tip Code Structure:
document.addEventListener("keydown", (event) => {
alert(event.key);
});
Expected Result:
When pressing the 'w' key:

Your completed projects must include:
Exercise 1 - Click Event:
addEventListener()Exercise 2 - Mouse Events:
Exercise 3 - Keyboard Events:
💡 Tip Common Issues:
text-danger class is included in your projectdocument, not a specific elementwindow.addEventListener('DOMContentLoaded', () => { ... })ℹ️ Ready to submit? When you have completed all three Event exercises, submit your projects using the link below:
Before submitting, test that:
- ✓ Button click shows alert
- ✓ Text changes color on hover
- ✓ Keyboard presses are detected