Every 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.
Three new kinds of block, all in the Apps category:
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.
The page already has a counter called score on it.
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}]}}
One button is a start. Two is a thing that works.
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));
});
})();Last piece: take something from the person using the page.
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}]}}
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.