Skip to content
UNWIND Code Lab Co-funded by the European Union
Project Step 4: Make Your Website Interactive
Log In

Project Step 4: Make Your Website Interactive

  • 5 min reading
  • 7 min activity
0 of 5 tasks doneup to 100 XP
  1. Tap, function, change10 XPTo do
  2. My website comes to life60 XPTo do
  3. Warm-up for the challenge10 XPOptional
  4. Warm-up for the challenge10 XPOptional
  5. Warm-up for the challenge10 XPOptional

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.

In this lesson
  • Greet visitors with a template literal.
  • Build your goals list from an array with a for loop.
  • Show and hide "More about me" with a button and a function.
Remember

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

PartHTML and CSSJavaScript
1. Greeting<p id="hello"></p> in the headerA template literal and textContent
2. GoalsA section with the id goals, a heading and an empty <ul id="goal-list">An array, a for loop, createElement(), appendChild()
3. More about meA 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.

Step by step

Tap, function, change

Required 10 XP

Worked example: the toggle function

Worked example
  1. Find

    const more = document.getElementById("more");

  2. Check

    if (more.style.display === "block"): is the box visible now?

  3. 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.

For screen readers

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.

Practice

My website comes to life

Required 60 XP

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.

Quick check

Warm-up for the challenge

10 XP
Quick check

Warm-up for the challenge

10 XP
Quick check

Warm-up for the challenge

10 XP
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 textContent greet your visitors.
  • An array and a for loop build the goals list.
  • A tap calls a function; if and else show or hide the box.
  • Connect the button with addEventListener() (recommended) or onclick, not both.
Next time

Save your website as your first portfolio item, decide who may see it, and look back at your journey.

Sources

  1. MDN Web Docs (2026). Introduction to events.
  2. MDN Web Docs (2026). EventTarget: addEventListener() method.
  3. MDN Web Docs (2026). HTMLElement: style property.
  4. MDN Web Docs (2026). aria-expanded.

End of the lesson

This lesson: 0 of 110 XP

Code Cards in this lesson: 2

  • onclick
  • addEventListener()