As a new developer at a tech company, you are tasked with creating a dynamic user interface for a simple web application. You’ll add interactive features using event listeners to respond to user actions like clicking buttons and pressing keys. This is a common task in modern web development, where creating responsive and engaging interfaces is crucial.
- Handle Button Clicks
- Capture Keyboard Input
- Process Text Input
- Combine Multiple Events
- Implement Additional Features
-
Fork and Clone the Repository:
- Go to the provided GitHub repository link.
- Fork the repository to your GitHub account.
- Clone the forked repository to your local machine.
- Open the project in VSCode.
- Run
npm install
to install all necessary dependencies.
-
Handle Button Clicks
- Create a function
changeBackgroundColor()
that changes the background color of the page when a button is clicked. - Reset the background color to white by building a function
resetBackgroundColor()
and attaching it to a double-click event.
- Create a function
-
Capture Keyboard Input
- Build a function
displayKeyPress(event)
that updates a paragraph to display the key pressed by the user. - Attach the function to a keydown event listener on the document.
- Build a function
-
Process Text Input
- Create a function
displayUserInput()
that shows real-time input in a paragraph as the user types into a text field. - Attach the function to the input event of a text field.
- Create a function
-
Combine Multiple Events
- Develop a function that integrates button clicks, key presses, and text input to create more dynamic interactions on the page.
- Apply event listeners to perform different tasks based on user interactions.
-
BONUS CHALLENGE: Implement Additional Features
- Explore additional event types and integrate more complex interactivity.
- Ensure the application responds smoothly to rapid user interactions.
Handling additional user interactions can further enhance the user experience. Here are some ideas:
Use mouseover
and mouseout
events to change element styles when hovering over them:
someElement.addEventListener('mouseover', () => {
someElement.style.backgroundColor = 'yellow';
});
someElement.addEventListener('mouseout', () => {
someElement.style.backgroundColor = 'initial';
});
Handle form submissions to process user inputs:
formElement.addEventListener('submit', (event) => {
event.preventDefault();
// Process form data
});