Recall & Review
beginner
What is JavaScript used for in web pages?
JavaScript is used to make web pages interactive. It can respond to user actions like clicks, typing, and mouse movements to change the page without reloading.
Click to reveal answer
beginner
Explain the role of an event listener in JavaScript.
An event listener waits for a specific action (like a click) on a webpage element and then runs a function when that action happens.
Click to reveal answer
beginner
What does the following JavaScript code do?<br>
document.getElementById('btn').addEventListener('click', () => { alert('Hello!'); });This code waits for a click on the element with id 'btn'. When clicked, it shows a popup message saying 'Hello!'.
Click to reveal answer
beginner
Why is JavaScript called a 'client-side' language?
Because JavaScript runs in the user's web browser (the client), not on the web server. This lets pages react quickly to user actions.
Click to reveal answer
intermediate
How does JavaScript change the content of a web page without reloading it?
JavaScript can change the page by modifying the HTML elements directly using the Document Object Model (DOM), so the page updates instantly.
Click to reveal answer
What does an event listener do in JavaScript?
✗ Incorrect
An event listener waits for user actions like clicks or typing and runs code when those actions occur.
Which JavaScript method selects an element by its ID?
✗ Incorrect
document.getElementById() selects a single element by its unique ID.
What happens when you run this code?<br>
button.addEventListener('click', () => { console.log('Clicked!'); });✗ Incorrect
The code logs the message to the browser console when the button is clicked.
Why is JavaScript important for web interactivity?
✗ Incorrect
JavaScript allows web pages to respond instantly to user actions, improving user experience.
Which of these is NOT a typical use of JavaScript on a web page?
✗ Incorrect
JavaScript runs in the browser and does not create or manage server databases.
Describe how JavaScript makes a web page interactive using an example.
Think about clicking a button and what happens next.
You got /4 concepts.
Explain the role of the Document Object Model (DOM) in JavaScript interactivity.
Imagine the web page as a tree of elements JavaScript can change.
You got /3 concepts.