JavaScript
Intermediate
40 mins
Teacher/Student led
+110 XP

Studio: Make Your Page Do Something

An optional studio build, and the only session that uses the builder's Apps blocks. Pupils build a counter changed by buttons and a text box that adds what somebody types to a list, then find the JavaScript the blocks wrote.

Teacher Class Feed

Load previous activity

    1 - Start: What We're Building ~3 mins

    Illustration for Start: what we're buildingEvery page you have built has been the same page for everybody who opens it. Today it changes while somebody uses it.

    Getting started: open the builder on the next step. It has a small counter page in it to work on.

    You will build a counter a button changes, and a box people can type into that adds what they typed to a list.

    2 - A Click Can Run Instructions ~4 mins

    Three new kinds of block, all in the Apps category:

    • A counter is a number on the page with a name.
    • A text box is somewhere a reader can type.
    • A button when clicked holds action blocks, and runs them on each click.

    The blocks inside the button are the instructions. The button is what starts them. That is the same shape as the events you used in Strand 1: something happens, then a list of instructions runs.

    3 - Make a Button Change a Counter ~8 mins

    The page already has a counter called score on it.

    1. From Apps, drag a button when clicked block onto the page, under the counter, and label it something like "Goal".
    2. From Apps, drag a change counter block and drop it inside the button, in the gap in it.
    3. Leave the dropdown on score and the amount on 1.
    4. Before you click it, predict out loud what the number will do on the first click, and what it will do on the fifth.
    5. Open Your web page and click your button several times. Were you right?

    Here are the blocks:

    {"blocks": {"languageVersion": 0, "blocks": [{"type": "wp_counter", "fields": {"NAME": "score", "START": 0}, "next": {"block": {"type": "wp_do_button", "fields": {"LABEL": "Goal"}, "inputs": {"DO": {"block": {"type": "wp_act_change", "fields": {"COUNTER": "score", "AMOUNT": 1}}}}}}, "x": 10, "y": 10}]}}

    Interactive activity

    4 - Add a Reset, and Read What the Blocks Wrote ~7 mins

    One button is a start. Two is a thing that works.

    1. Add a second button when clicked block from Apps, labelled "Reset".
    2. Put a set counter block inside it, on score, to 0.
    3. Test both buttons.
    4. Now open the HTML tab and scroll to the very bottom, past your page. There is a block of instructions the blocks wrote for you. Find counter-score in it: that is your counter, looked up by name.

    That is JavaScript, the third web language. You are not writing it today, but that is where a button's behaviour lives. The jumble after btn- will be different on your screen: it is the name the builder gave your button. Here is what your Goal button wrote:

    (function () {
      var b = document.getElementById("btn-k5LnxF2vQ");
      if (!b) return;
      b.addEventListener("click", function () {
        var c = document.getElementById("counter-score"); if (c) c.textContent = String((Number(c.textContent) || 0) + (1));
      });
    })();

    Interactive activity

    5 - A Box People Can Type Into ~8 mins

    Last piece: take something from the person using the page.

    1. From Apps, add a text box block and a list box block to the page.
    2. Add another button when clicked, labelled "Add".
    3. Inside that button, put an add text box to list box block, with the dropdowns pointing at the two you just made.
    4. Test it: type something, click Add, and watch it appear in the list.

    Here are the blocks:

    {"blocks": {"languageVersion": 0, "blocks": [{"type": "wp_input", "fields": {"NAME": "name", "PLACEHOLDER": "Type here..."}, "next": {"block": {"type": "wp_listbox", "fields": {"NAME": "things"}, "next": {"block": {"type": "wp_do_button", "fields": {"LABEL": "Add"}, "inputs": {"DO": {"block": {"type": "wp_act_add", "fields": {"INPUT": "name", "LIST": "things"}}}}}}}}, "x": 10, "y": 10}]}}

    Interactive activity

    123learn · Online learning platform

    Unlock the full learning experience

    You're previewing this lesson. Get full access to this lesson and hundreds more — each one ready to teach, with interactive activities, printable resources and pupil progress tracking built in.

    Hundreds of curriculum-aligned lessons
    Interactive activities in every lesson
    Printable resources & progress tracking
    Copyright Notice
    This lesson is copyright of Coding Ireland 2017 - 2025. Unauthorised use, copying or distribution is not allowed.
    🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more