Project Step 4: Make Your Website Interactive
- 5 min reading
- 7 min activity
0 of 5 tasks doneup to 100 XP
Mission 4, the last building step. Your website gets three small pieces of behaviour: a greeting, a list of your goals, and a button that shows more about you.
- Greet visitors with a template literal.
- Build your goals list from an array with a
forloop. - Show and hide "More about me" with a button and a function.
Which three steps add a new list item to a page? Think first, then open the answer.
Show the answer
Make it with document.createElement("li"), fill it with textContent, and add it with appendChild(). You did this in lesson 4.2.
The plan
| Part | HTML and CSS | JavaScript |
|---|---|---|
| 1. Greeting | <p id="hello"></p> in the header | A template literal and textContent |
| 2. Goals | A section with the id goals, a heading and an empty <ul id="goal-list"> | An array, a for loop, createElement(), appendChild() |
| 3. More about me | A button with the id more-btn and a box with the id more in the side area; CSS #more { display: none; } | A function with if and else that changes style.display |
How a tap runs your code
A button needs a function and a connection. The course slides on buttons (Part 2) connect them in the HTML with the attribute onclick:
<button type="button" onclick="toggleMore()">More about me</button>
Today most developers connect them in the JavaScript with addEventListener(), so HTML and JavaScript stay apart. We recommend this way:
document.getElementById("more-btn").addEventListener("click", toggleMore);
Write the function name without brackets here: the browser calls it later, at the tap. Use one of the two ways, not both, or the function runs twice.
Tap, function, change
Worked example: the toggle function
- Find
const more = document.getElementById("more"); - Check
if (more.style.display === "block"): is the box visible now? - Change
If yes, hide it with
"none". If not, show it with"block".
function toggleMore() {
const more = document.getElementById("more");
if (more.style.display === "block") {
more.style.display = "none";
} else {
more.style.display = "block";
}
}
At the start your CSS hides the box, but style.display is still empty: it only shows styles that JavaScript set. So the first tap goes to else and shows the box. The second tap hides it again.
Give the button aria-expanded="false", and in the function set it to "true" when the box opens: button.setAttribute("aria-expanded", "true"). Then screen readers can tell visitors that the box is open.
Your turn: bring your website to life
The exercise starts with your website from Project Step 3. Use the chips to add the new HTML, CSS and JavaScript, part by part, then check. Use your own name and goals; a nickname is fine. This step earns the First Interaction badge.
My website comes to life
Project step 4: your website from Project Step 3 is loaded. Add a greeting, your goals and a "More about me" button, part by part.
In a real website, save the JavaScript as script.js and add <script src="script.js"></script> right before </body>. Here the JavaScript tab does this for you.
Warm-up for the challenge
Three optional questions before the Unit 4 challenge. They give extra XP.
Warm-up for the challenge
Warm-up for the challenge
Warm-up for the challenge
- Event
- Something that happens on the page, like a click or a tap.
- onclick
- An HTML attribute that runs JavaScript at a click or tap.
- addEventListener()
- Connects an event to a function, from the JavaScript.
- Toggle
- Switch between two states: open, closed, open again.
In short
- A template literal and
textContentgreet your visitors. - An array and a
forloop build the goals list. - A tap calls a function;
ifandelseshow or hide the box. - Connect the button with
addEventListener()(recommended) oronclick, not both.
Save your website as your first portfolio item, decide who may see it, and look back at your journey.
Sources
- MDN Web Docs (2026). Introduction to events.
- MDN Web Docs (2026). EventTarget: addEventListener() method.
- MDN Web Docs (2026). HTMLElement: style property.
- MDN Web Docs (2026). aria-expanded.
End of the lesson
This lesson: 0 of 110 XP
Code Cards in this lesson: 2
onclickaddEventListener()