JavaScript · Lesson 1 of 4
Make a button change a message
getElementById finds an element by its ID. addEventListener connects a click to your instructions, and textContent changes the displayed text.
Your task
Change the greeting, run the code, then click the button in the result.
Each new lesson builds on your personal page. Your saved lesson draft opens when you return.
The image stays in your browser. Choose it, then use its filename when you add the image to your code.
Edit your project HTML and CSS
Your page
Checks use your current code. Try the page yourself too.
Your feedback
Did your message appear after clicking? Move on to counting clicks.
Next: A counterI need help
First change just the text between quotation marks. Run the code, then click “Say hello” in the result. greet must match the button’s ID in HTML.
Save the page to your computer
If the download does not start, copy the complete code below into a text file named index.html and save it as UTF-8.