Software EngineeringAlliance Girls High School
TERM 3 / WEEK 04

JULY 27 · MODULE 4

Introduction to Programming I

WEEK 4 · JULY 27 · JAVASCRIPT

Click something.
Make it respond.

Build an activity finder. Then adapt the interaction for your capstone.

Type every example yourself. Check the result before moving to the next slide.

TOFA × Alliance Girls AlumniGrade 10 · Term 3
01

SET UP · 5 MIN

Give JavaScript
a place to work.

<button id="show" type="button">Show activities</button>
<ul id="activities"></ul>
<p id="status" role="status"></p>

Add this to index.html in NitroIDE. Write your JavaScript in script.js; NitroIDE runs it after your HTML, so no script tag is needed.

02

BUILD ALONG · SCRIPT.JS · 5 MIN

Data + elements.
Meet your ingredients.

const activities = ["Coding club", "Design challenge"];
const list = document.querySelector("#activities");
const status = document.querySelector("#status");
const button = document.querySelector("#show");
console.log(activities.length);

const names a value; an array stores a list. Open DevTools → Console. Expect 2. Add an activity—what changes?

03

BUILD ALONG · APPEND TO SCRIPT.JS · 7 MIN

A function is
a reusable recipe.

function addActivity(name) {
  const item = document.createElement("li");
  item.textContent = name;
  list.append(item);
}
addActivity("Try a new skill");

The parameter name receives your text. See one list item? Remove just the last test call before continuing.

04

BUILD ALONG · APPEND TO SCRIPT.JS · 7 MIN

One instruction.
Every activity.

function showActivities() {
  list.replaceChildren();
  for (const activity of activities) {
    addActivity(activity);
  }
}
showActivities();

The loop visits each item. Why clear the list first? Run it twice, then remove the last test call.

05

BUILD ALONG · INSIDE SHOWACTIVITIES · 7 MIN

If this happens,
say that.

if (activities.length === 0) {
  status.textContent = "No activities yet.";
} else {
  status.textContent = "Choose an activity to explore.";
}

Insert after the loop, before the function’s final }. The condition chooses feedback for an empty or full list.

06

BUILD ALONG · BOTTOM OF SCRIPT.JS · 5 MIN

Now connect
the click.

button.addEventListener("click", showActivities);
  • ClickYour list should appear.
  • RepeatClick again. No duplicate items.
  • KeyboardTab to the button. Press Enter.
07

BUG HUNT · DELIBERATELY BROKEN · 5 MIN

The button
does nothing.

const button = document.querySelector("#Show");
button.addEventListener("click", showActivities);

Compare the selector with your HTML id. What does the Console tell you?

Read the error → find the line → check your assumption → fix → retest. Keep only one button declaration.

08

BUG HUNT · DELIBERATELY BROKEN · 5 MIN

It runs now.
Not on click.

button.addEventListener("click", showActivities());

Which two characters run the function immediately?

Pass the function, don’t call it. Compare with slide 7, fix the listener and reload.

09

PAIR TEST · 8 MIN

Try to
break it kindly.

  • EmptySet activities to []. Check the empty message.
  • ManyAdd five activities. Does every one appear?
  • RepeatClick three times. Check for duplicates and Console errors.

Restore your useful data. Record expected result → actual result → fix.

10

CAPSTONE SPRINT · 15 MIN

Make it useful
for your users.

  • OpportunitiesShow activities for a chosen interest.
  • WeatherChoose a town and show a sample forecast.
  • CyberSmartCheck a quiz answer and explain the safer choice.

Choose one interaction. Use labelled controls and visible feedback. No personal-data collection.

11

THIS WEEK · SHOW IT WORKING

Not just a page.
An experience.

  • BuildAdd one interactive feature to your capstone.
  • ExplainPoint to a function, loop and condition.
  • DebugSave two bug/fix notes and your test results.

Next: add interactivity at home in Lesson 5 →

12
01/12

← → to navigate · F fullscreen

Slide 1 of 12