← Teacher guide

Build around a simulation

Optional extension: an Embed shows a ready-made pendulum simulation (one web page, pendulum.html in this folder). The page sends period and length; the app sends gravity. Students build the app around it: Sim sends period shows the period (Build 1), planet buttons send gravity (Build 2), Record adds a row to Readings (Build 3). The Check shows that only the names in Sends get through. Then students use the lab to answer a science question and add a Clear button.

Data apps · Build around a simulation · about 45 minutes · Open the student lesson

Classroom resources

Open these in Waypoints Prepare with one click. To share a file another way, copy its address and paste it into Load URL, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.

Students will be able to

Timing

Try 5 min · Builds 1–3 20 min · Check 3 min · Use your lab 10 min · Make it yours 7 min

Before class

Needs App Builder 1.13 (the Embed object and its messages, Level 4). The simulation is a single web page; the app never changes it. The page runs in a safe box: it can't see the rest of the app or anything saved in the browser, and the app only takes the message names listed in Sends, each with one plain value.

The page is the same one as App Builder's Pendulum lab sample. You can make your own for another topic: in an Embed's Properties, fill in Sends and Listens for, then Copy a prompt for an AI chat gives a prompt that asks for a page using those names. Paste the page it gives back with + Paste HTML. Use only an AI chat your school allows; check the page works before a class uses it.

The physics: a simple pendulum's period is 2π√(L/g), so it grows with length and shrinks with gravity, and doesn't depend on the bob's mass (for small swings). The page works the period out from that formula, so readings are exact; a real pendulum's would vary.

Running the lesson

  1. Before Build 1 (whole class): open Sim's Properties. What does the simulation tell the app? What can the app tell it?
  2. Use your lab: collect a few rows from the class on the board and look for the pattern together.

In class

On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.

The hard part (on purpose)

Seeing the simulation as a part with inputs and outputs: point at the Sends and Listens for boxes in Sim's Properties before Build 1.

When students get stuck

What you will seeA question to askThe fix
Sim sends period isn't in the list.Which group are you looking in?It's in Sim's group (the object), not System. Sim must list period under Sends in its Properties.
An error says Sim hasn't sent period yet.When did the page last send a value?Run the app and wait a moment, or drag Length: the page sends its values when it starts and whenever they change.
Clicking Moon changes the text but not the swing.Is there a Send gravity action, and what does it send?Add Send gravity = Gravity to Sim after setting the variable.

Answers to the checks

  1. Check: what gets through?: The pendulum page also sends a message called angle. Sim's Sends box says only period, length. What happens when angle arrives?
    Nothing: the app ignores it
    The Embed only lets through the names in its Sends box, and only one plain value each: a number, some text, true or false. To use angle, add it to Sends; then there's a Sim sends angle event and a Sim.angle value.

Solutions

One possible solution for each task. Other correct programs are fine.

Make it yours: start again › Clear the readings

{"version":1,"name":"Pendulum lab","device":"web","features":{"level":4},"variables":[{"name":"Gravity","value":9.8},{"name":"Readings","table":{"fields":[{"name":"length","type":"number"},{"name":"gravity","type":"number"},{"name":"period","type":"number"}]},"value":[]}],"screens":[{"id":"home","name":"Lab","objects":[{"name":"Title","kind":"text","instanceVars":[],"instances":[{"id":"p0","x":20,"y":12,"w":760,"h":32,"text":"Pendulum lab: what changes the period?","visible":true,"vars":{}}]},{"name":"Sim","kind":"embed","instanceVars":[],"instances":[{"id":"p1","x":20,"y":52,"w":460,"h":300,"text":"A pendulum: drag Length to change it","visible":true,"vars":{},"page":"pendulum","sends":"period, length","listens":"gravity"}]},{"name":"Planet","kind":"button","instanceVars":[{"name":"g","value":0}],"instances":[{"id":"p20","x":500,"y":52,"w":130,"h":40,"text":"Earth","visible":true,"vars":{"g":9.8}},{"id":"p21","x":500,"y":100,"w":130,"h":40,"text":"Moon","visible":true,"vars":{"g":1.6}},{"id":"p22","x":500,"y":148,"w":130,"h":40,"text":"Mars","visible":true,"vars":{"g":3.7}}]},{"name":"GravityText","kind":"text","instanceVars":[],"instances":[{"id":"p3","x":500,"y":200,"w":280,"h":26,"text":"Gravity: 9.8 m/s²","visible":true,"vars":{}}]},{"name":"PeriodText","kind":"text","instanceVars":[],"instances":[{"id":"p4","x":500,"y":230,"w":280,"h":26,"text":"Period: ","visible":true,"vars":{}}]},{"name":"Record","kind":"button","instanceVars":[],"instances":[{"id":"p5","x":500,"y":270,"w":160,"h":44,"text":"Record reading","visible":true,"vars":{}}]},{"name":"ReadingsView","kind":"table","instanceVars":[],"instances":[{"id":"p6","x":20,"y":368,"w":460,"h":210,"text":"","visible":true,"vars":{},"source":"Readings","columns":""}]},{"name":"Question","kind":"text","instanceVars":[],"instances":[{"id":"p7","x":500,"y":368,"w":280,"h":140,"text":"Record two lengths on Earth, then the same lengths on the Moon. What makes the period longer? What doesn’t change it?","visible":true,"vars":{}}]},{"name":"ClearButton","kind":"button","instanceVars":[],"instances":[{"id":"p8","x":670,"y":270,"w":110,"h":44,"text":"Clear","visible":true,"vars":{}}]}],"events":[{"id":"s1","else":false,"conds":[{"type":"onEmbedSends","target":"Sim","message":"period"}],"actions":[{"type":"setText","target":"PeriodText","value":"\"Period: \" & Sim.period & \" s\""}],"children":[]},{"id":"s2","else":false,"conds":[{"type":"onClicked","target":"Planet"}],"actions":[{"type":"setVar","var":"Gravity","value":"Planet.g"},{"type":"sendToEmbed","target":"Sim","message":"gravity","value":"Gravity"},{"type":"setText","target":"GravityText","value":"\"Gravity: \" & Gravity & \" m/s²\""}],"children":[]},{"id":"s3","else":false,"conds":[{"type":"onClicked","target":"Record"}],"actions":[{"type":"tableAdd","table":"Readings","values":{"length":"Sim.length","gravity":"Gravity","period":"Sim.period"}}],"children":[]},{"id":"s4","else":false,"conds":[{"type":"onClicked","target":"ClearButton"}],"actions":[{"type":"tableClear","table":"Readings"}],"children":[]}]}],"pages":[{"name":"pendulum","data":"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxodG1sPjxoZWFkPjxtZXRhIGNoYXJzZXQ9InV0Zi04Ij48dGl0bGU+UGVuZHVsdW08L3RpdGxlPgo8c3R5bGU+Ym9keXttYXJnaW46MDtmb250OjE0cHggc3lzdGVtLXVpLHNhbnMtc2VyaWY7YmFja2dyb3VuZDojZjRmN2ZmO292ZXJmbG93OmhpZGRlbn0KI2N7ZGlzcGxheTpibG9jazt3aWR0aDoxMDB2dztoZWlnaHQ6Y2FsYygxMDB2aCAtIDQ0cHgpfQouYmF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W92ZVRvKG94LCBveSk7IHgubGluZVRvKGJ4LCBieSk7IHguc3Ryb2tlKCk7CiAgeC5maWxsU3R5bGUgPSAnIzM1NjNlOSc7IHguYmVnaW5QYXRoKCk7IHguYXJjKGJ4LCBieSwgMTIsIDAsIDcpOyB4LmZpbGwoKTsKICB4LmZpbGxTdHlsZSA9ICcjMjIzJzsgeC5maWxsVGV4dCgnUGVyaW9kOiAnICsgcGVyaW9kKCkgKyAnIHMnLCAxMCwgaCAtIDEwKTsKICByZXF1ZXN0QW5pbWF0aW9uRnJhbWUoZHJhdyk7Cn0Kc2hvdygpOyB0ZWxsKCk7IGRyYXcoKTsKPC9zY3JpcHQ+PC9ib2R5PjwvaHRtbD4K"}]}

Make it yours: start again › One more idea

Open task: any program that does what the step asks.

Stretch and support

Stretch: Add a Sim sends length event that shows the length too. Why does the page send both, when the app could work out the period itself?

Support: Build 1 together with the clip; pairs do Builds 2 and 3.

Exit ticket

A climate simulation page sends temperature and listens for co2. Name the event and the action you would use in App Builder.

The event Sim sends temperature (with Sim.temperature as the value), and the action Send co2 = … to Sim.

What each step is for

Where it leads

Science: Year 10 physics on forces and motion. Code: the web pathway's DOM course, where pages send and receive messages in the same way.