Loading
0xF0Lesson 16 of 16

Capstone: an event availability board

Connect data, an async request, DOM updates and accessible feedback.

27 min 2-question quiz 1 code exercise
By the end of this lesson you can
  • Explain the responsibilities of HTML, CSS, browser JavaScript and server JavaScript
  • Render an asynchronous result safely
  • Handle both available and unavailable states

Imagine a venue listing workshop seats. HTML gives the page a heading, button and status element. CSS makes availability easy to scan. Browser JavaScript requests the latest count and updates the DOM. A Node.js API could read the inventory and return JSON. In this capstone you build the browser decision with a mock Promise so no server or account is needed.

board.html
1<h1>Workshop seats</h1>
2<button id="refresh" type="button">Refresh availability</button>
3<p id="availability" role="status">Choose refresh to check seats.</p>
4<script src="board.js" defer></script>
board.css
.open { color: #126245; }
.full { color: #9b2727; }
#availability { font-weight: 700; }
board.js (browser)
1const status = document.querySelector("#availability");
2document.querySelector("#refresh").addEventListener("click", async () => {
3  status.textContent = "Checking…";
4  try {
5    const response = await fetch("/api/seats");
6    if (!response.ok) throw new Error("HTTP " + response.status);
7    const data = await response.json();
8    status.textContent = data.seats > 0 ? data.seats + " seats open" : "Fully booked";
9    status.classList.toggle("open", data.seats > 0);
10    status.classList.toggle("full", data.seats === 0);
11  } catch { status.textContent = "Could not check seats. Try again."; }
12});

Try it

Up to 15 XP

Trace the full stack

Follow the request from the browser to a Node server and back. Predict which side controls the visible message.

Message 1 of 4Predicted 0/0
HTML/CSS page
Browser JavaScript
Node API
DOM status

Real teams use this pattern for stock availability, order status, appointment slots and dashboards. Before releasing it, test the zero, positive and failure cases. Check the page with a keyboard and a screen reader; a status message should be announced without taking focus away from the button.

Key takeaways

  • Keep structure, style, browser behavior and server data responsibilities clear.

  • Render user-visible state with textContent and CSS classes.

  • Test zero, positive and failure results, not just the happy path.

Lesson quiz

2 questions · pass with 2 correct · up to 50 XP

Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.

Practice: write JavaScript

Write the program, run it against the test cases, and use the feedback to build your JavaScript skills.

Exercise 1

Render every availability state

+25 XP

The starter creates a status paragraph in the isolated exercise page. Input is ok,N or error,N. Await the mock request. On success, set the paragraph to N seats open if N is positive, or Fully booked if zero; on error, set it to Could not check seats. Print its textContent.

  • Seats open
  • Full
  • Request failed
main.js
Loading editor…

JavaScript runs in a sandboxed browser frame with a 1.5 second time limit. Input is available as the string variable input.

Questions about this lesson

Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.

Loading posts…