Students read fields of records: ClickedItem.title for a Now playing line, LoopItem.length inside For each row to total the lengths (an accumulator), and a variable holding a whole row to find the longest song (a running maximum). The Check traces the total and finds Nib resetting it inside the loop. Make it yours: the average with count(), and the shortest song.
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.
Try 5 min · Build 1–3 30 min · Check 10 min · Make it yours 15 min
These are the first named algorithms of the course: the accumulator (running total) and the running maximum (best so far). Name them as algorithm ideas, not App Builder features: they come back in Python and spreadsheets.
A variable can hold one whole row: Set variable longest to item(Songs, 1), then longest.title. While the app runs, the sidebar shows it as { title: ..., artist: ..., length: ... }.
A sub-event with no condition always runs; put it after the loop to show the result.
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.
A running total and a best so far: two patterns that come back in every language.
Read the lengths 3, 5, 4, 2 aloud. After each, the class says the total so far: 3, 8, 12, 14. Then do it again, holding up the longest so far.
Where does the total start, and when? That's the slip Nib makes in the Check.
Where each part sits: start the total on the parent event, add inside the loop, show it in a sub-event after the loop. The order of sub-events matters, and the actions of an event run before its sub-events.
| What you will see | A question to ask | The fix |
|---|---|---|
| The total is only the last song's length. | Where does total go back to 0? | Set total to 0 on the parent event, not inside the For each row sub-event. |
| TotalText shows 0. | Does the sub-event that sets the text come after the loop? | Put the no-condition sub-event below the For each row sub-event. |
| Longest shows nothing or an error about a field. | What does longest hold before the loop starts? | Start it with Set variable longest to item(Songs, 1), so longest.length exists. |
One possible solution for each task. Other correct programs are fine.
{"version":1,"name":"Playlist records","device":"web","features":{"level":4},"variables":[{"name":"Songs","table":{"fields":[{"name":"title","type":"text"},{"name":"artist","type":"text"},{"name":"length","type":"number"}]},"value":[{"title":"Blue Sky","artist":"Kai","length":3},{"title":"Arc","artist":"Mo","length":5},{"title":"Cove","artist":"Lu","length":4},{"title":"Nova","artist":"Kai","length":2}]},{"name":"total","value":0},{"name":"longest","value":""},{"name":"shortest","value":""}],"screens":[{"id":"home","name":"Home","objects":[{"name":"Title","kind":"text","instanceVars":[],"instances":[{"id":"h1","x":24,"y":16,"w":500,"h":40,"text":"My playlist","visible":true,"vars":{}}]},{"name":"TitleLabel","kind":"text","instanceVars":[],"instances":[{"id":"l1","x":24,"y":64,"w":60,"h":36,"text":"Title","visible":true,"vars":{}}]},{"name":"TitleInput","kind":"input","instanceVars":[],"instances":[{"id":"i1","x":84,"y":60,"w":170,"h":42,"text":"","visible":true,"vars":{}}]},{"name":"ArtistLabel","kind":"text","instanceVars":[],"instances":[{"id":"l2","x":268,"y":64,"w":60,"h":36,"text":"Artist","visible":true,"vars":{}}]},{"name":"ArtistInput","kind":"input","instanceVars":[],"instances":[{"id":"i2","x":328,"y":60,"w":150,"h":42,"text":"","visible":true,"vars":{}}]},{"name":"LengthLabel","kind":"text","instanceVars":[],"instances":[{"id":"l3","x":492,"y":64,"w":70,"h":36,"text":"Minutes","visible":true,"vars":{}}]},{"name":"LengthInput","kind":"input","instanceVars":[],"instances":[{"id":"i3","x":566,"y":60,"w":70,"h":42,"text":"","visible":true,"vars":{}}]},{"name":"AddButton","kind":"button","instanceVars":[],"instances":[{"id":"b1","x":650,"y":58,"w":130,"h":46,"text":"Add song","visible":true,"vars":{}}]},{"name":"SongTable","kind":"table","instanceVars":[],"instances":[{"id":"T1","x":24,"y":120,"w":560,"h":230,"text":"","visible":true,"vars":{},"source":"Songs","columns":""}]},{"name":"NowText","kind":"text","instanceVars":[],"instances":[{"id":"t1","x":24,"y":360,"w":560,"h":32,"text":"Click a song to play it","visible":true,"vars":{}}]},{"name":"TotalButton","kind":"button","instanceVars":[],"instances":[{"id":"b2","x":600,"y":130,"w":180,"h":46,"text":"Total length","visible":true,"vars":{}}]},{"name":"TotalText","kind":"text","instanceVars":[],"instances":[{"id":"t2","x":600,"y":182,"w":180,"h":32,"text":"","visible":true,"vars":{}}]},{"name":"LongestButton","kind":"button","instanceVars":[],"instances":[{"id":"b3","x":600,"y":230,"w":180,"h":46,"text":"Longest song","visible":true,"vars":{}}]},{"name":"LongestText","kind":"text","instanceVars":[],"instances":[{"id":"t3","x":600,"y":282,"w":180,"h":50,"text":"","visible":true,"vars":{}}]},{"name":"ShortestButton","kind":"button","instanceVars":[],"instances":[{"id":"b4","x":600,"y":340,"w":180,"h":46,"text":"Shortest song","visible":true,"vars":{}}]},{"name":"ShortestText","kind":"text","instanceVars":[],"instances":[{"id":"t4","x":600,"y":392,"w":180,"h":50,"text":"","visible":true,"vars":{}}]}],"events":[{"id":"e1","else":false,"conds":[{"type":"onClicked","target":"AddButton"}],"actions":[{"type":"tableAdd","table":"Songs","values":{"title":"TitleInput.text","artist":"ArtistInput.text","length":"int(LengthInput.text)"}}],"children":[]},{"id":"e2","else":false,"conds":[{"type":"onItemClicked","target":"SongTable"}],"actions":[{"type":"setText","target":"NowText","value":"\"Now playing: \" & ClickedItem.title & \" by \" & ClickedItem.artist"}],"children":[]},{"id":"e3","else":false,"conds":[{"type":"onClicked","target":"TotalButton"}],"actions":[{"type":"setVar","var":"total","value":"0"}],"children":[{"id":"e3a","else":false,"conds":[{"type":"forEachRow","table":"Songs"}],"actions":[{"type":"addTo","var":"total","value":"LoopItem.length"}],"children":[]},{"id":"e3b","else":false,"conds":[],"actions":[{"type":"setText","target":"TotalText","value":"\"Total: \" & total & \" min, average \" & round(total / count(Songs))"}],"children":[]}]},{"id":"e4","else":false,"conds":[{"type":"onClicked","target":"LongestButton"}],"actions":[{"type":"setVar","var":"longest","value":"item(Songs, 1)"}],"children":[{"id":"e4a","else":false,"conds":[{"type":"forEachRow","table":"Songs"},{"type":"compareValues","left":"LoopItem.length","op":">","right":"longest.length"}],"actions":[{"type":"setVar","var":"longest","value":"LoopItem"}],"children":[]},{"id":"e4b","else":false,"conds":[],"actions":[{"type":"setText","target":"LongestText","value":"\"Longest: \" & longest.title"}],"children":[]}]}]}]}
{"version":1,"name":"Playlist records","device":"web","features":{"level":4},"variables":[{"name":"Songs","table":{"fields":[{"name":"title","type":"text"},{"name":"artist","type":"text"},{"name":"length","type":"number"}]},"value":[{"title":"Blue Sky","artist":"Kai","length":3},{"title":"Arc","artist":"Mo","length":5},{"title":"Cove","artist":"Lu","length":4},{"title":"Nova","artist":"Kai","length":2}]},{"name":"total","value":0},{"name":"longest","value":""},{"name":"shortest","value":""}],"screens":[{"id":"home","name":"Home","objects":[{"name":"Title","kind":"text","instanceVars":[],"instances":[{"id":"h1","x":24,"y":16,"w":500,"h":40,"text":"My playlist","visible":true,"vars":{}}]},{"name":"TitleLabel","kind":"text","instanceVars":[],"instances":[{"id":"l1","x":24,"y":64,"w":60,"h":36,"text":"Title","visible":true,"vars":{}}]},{"name":"TitleInput","kind":"input","instanceVars":[],"instances":[{"id":"i1","x":84,"y":60,"w":170,"h":42,"text":"","visible":true,"vars":{}}]},{"name":"ArtistLabel","kind":"text","instanceVars":[],"instances":[{"id":"l2","x":268,"y":64,"w":60,"h":36,"text":"Artist","visible":true,"vars":{}}]},{"name":"ArtistInput","kind":"input","instanceVars":[],"instances":[{"id":"i2","x":328,"y":60,"w":150,"h":42,"text":"","visible":true,"vars":{}}]},{"name":"LengthLabel","kind":"text","instanceVars":[],"instances":[{"id":"l3","x":492,"y":64,"w":70,"h":36,"text":"Minutes","visible":true,"vars":{}}]},{"name":"LengthInput","kind":"input","instanceVars":[],"instances":[{"id":"i3","x":566,"y":60,"w":70,"h":42,"text":"","visible":true,"vars":{}}]},{"name":"AddButton","kind":"button","instanceVars":[],"instances":[{"id":"b1","x":650,"y":58,"w":130,"h":46,"text":"Add song","visible":true,"vars":{}}]},{"name":"SongTable","kind":"table","instanceVars":[],"instances":[{"id":"T1","x":24,"y":120,"w":560,"h":230,"text":"","visible":true,"vars":{},"source":"Songs","columns":""}]},{"name":"NowText","kind":"text","instanceVars":[],"instances":[{"id":"t1","x":24,"y":360,"w":560,"h":32,"text":"Click a song to play it","visible":true,"vars":{}}]},{"name":"TotalButton","kind":"button","instanceVars":[],"instances":[{"id":"b2","x":600,"y":130,"w":180,"h":46,"text":"Total length","visible":true,"vars":{}}]},{"name":"TotalText","kind":"text","instanceVars":[],"instances":[{"id":"t2","x":600,"y":182,"w":180,"h":32,"text":"","visible":true,"vars":{}}]},{"name":"LongestButton","kind":"button","instanceVars":[],"instances":[{"id":"b3","x":600,"y":230,"w":180,"h":46,"text":"Longest song","visible":true,"vars":{}}]},{"name":"LongestText","kind":"text","instanceVars":[],"instances":[{"id":"t3","x":600,"y":282,"w":180,"h":50,"text":"","visible":true,"vars":{}}]},{"name":"ShortestButton","kind":"button","instanceVars":[],"instances":[{"id":"b4","x":600,"y":340,"w":180,"h":46,"text":"Shortest song","visible":true,"vars":{}}]},{"name":"ShortestText","kind":"text","instanceVars":[],"instances":[{"id":"t4","x":600,"y":392,"w":180,"h":50,"text":"","visible":true,"vars":{}}]}],"events":[{"id":"e1","else":false,"conds":[{"type":"onClicked","target":"AddButton"}],"actions":[{"type":"tableAdd","table":"Songs","values":{"title":"TitleInput.text","artist":"ArtistInput.text","length":"int(LengthInput.text)"}}],"children":[]},{"id":"e2","else":false,"conds":[{"type":"onItemClicked","target":"SongTable"}],"actions":[{"type":"setText","target":"NowText","value":"\"Now playing: \" & ClickedItem.title & \" by \" & ClickedItem.artist"}],"children":[]},{"id":"e3","else":false,"conds":[{"type":"onClicked","target":"TotalButton"}],"actions":[{"type":"setVar","var":"total","value":"0"}],"children":[{"id":"e3a","else":false,"conds":[{"type":"forEachRow","table":"Songs"}],"actions":[{"type":"addTo","var":"total","value":"LoopItem.length"}],"children":[]},{"id":"e3b","else":false,"conds":[],"actions":[{"type":"setText","target":"TotalText","value":"\"Total: \" & total & \" min\""}],"children":[]}]},{"id":"e4","else":false,"conds":[{"type":"onClicked","target":"LongestButton"}],"actions":[{"type":"setVar","var":"longest","value":"item(Songs, 1)"}],"children":[{"id":"e4a","else":false,"conds":[{"type":"forEachRow","table":"Songs"},{"type":"compareValues","left":"LoopItem.length","op":">","right":"longest.length"}],"actions":[{"type":"setVar","var":"longest","value":"LoopItem"}],"children":[]},{"id":"e4b","else":false,"conds":[],"actions":[{"type":"setText","target":"LongestText","value":"\"Longest: \" & longest.title"}],"children":[]}]},{"id":"e5","else":false,"conds":[{"type":"onClicked","target":"ShortestButton"}],"actions":[{"type":"setVar","var":"shortest","value":"item(Songs, 1)"}],"children":[{"id":"e5a","else":false,"conds":[{"type":"forEachRow","table":"Songs"},{"type":"compareValues","left":"LoopItem.length","op":"<","right":"shortest.length"}],"actions":[{"type":"setVar","var":"shortest","value":"LoopItem"}],"children":[]},{"id":"e5b","else":false,"conds":[],"actions":[{"type":"setText","target":"ShortestText","value":"\"Shortest: \" & shortest.title"}],"children":[]}]}]}]}
Stretch: Show how many songs are longer than 3 minutes (a count with a condition).
Support: Build the total together, saying each step aloud; pairs do the longest song.
A table Scores has a field points. Write the three parts of an event that adds up every row's points into a variable sum.
Set sum to 0 on the event; a sub-event For each row in table Scores that adds LoopItem.points to sum; then a sub-event after it that shows sum.
Next: Saving between visits.