Respond to a click
JavaScript can change a page while someone uses it. document.querySelector("#id") finds an element by its id.
addEventListener("click", ...) runs a function every time the element is clicked. Inside it, setting textContent replaces the element's text.
Click the button in the preview to test your code yourself. The checks also click it for you.
Example
<button id="btn">Clicked 0 times</button>
<script>
let count = 0;
const btn = document.querySelector("#btn");
btn.addEventListener("click", () => {
count++;
btn.textContent = "Clicked " + count + " times";
});
</script>
The code you want to run on click goes inside the curly braces of the arrow function:
() => { … }.Your tasks
0 of 2 done- Use addEventListener to listen for a click
- Clicking the button changes the message text
Tutor
The tutor guides you toward the answer instead of handing it over. It uses your own Claude usage.
Quick check
What does querySelector("#message") find?
Nothing printed yet.
No problems found. Unclosed tags, missing semicolons and errors show up here in plain words.