Students sort the Songs table by a field (titles A to Z, longest first), then build search and filter with one algorithm: clear a Results table, go through every row of Songs with For each row, and copy the rows whose test passes. The Check finds Nib removing the non-matching rows (data lost) and shows why numbers kept as text sort wrongly. Make it yours: search two fields, and Show all.
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
Search and filter are the same algorithm (a linear search: test every row, keep the matches), with a different test. Name it as an algorithm students will meet again in Python and SQL.
Results starts empty and is cleared at the start of each search, so old results don't stay (the same idea as list-clear-before-add, the other way round).
App Builder's Sort is a tool, not an algorithm students write: it sorts numbers by size, text A to Z ignoring capitals, and keeps equal rows in their order.
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.
Look at every row, write down the matches: a linear search. The original list stays as it was.
Write 10, 9 and 3 on cards as words of text and sort them like a dictionary, by first character. Then sort them by size.
Text sorts character by character: 10, 3, 9. That's why length is a number field.
The search condition: contains(lower(LoopItem.title), lower(SearchInput.text)) = true is long. Build it in parts in the Find expressions browser, and test with a single letter.
| What you will see | A question to ask | The fix |
|---|---|---|
| Search finds nothing. | What does the condition compare, and with what? | Compare contains(lower(LoopItem.title), lower(SearchInput.text)) = true, inside the For each row sub-event. |
| Results keeps the last search's songs too. | Where is Results cleared? | Clear table Results as the parent event's action, before the loop. |
| Sorting by length puts 10 before 9. | What type is the length field? | Make length a Number field (click its name in the sidebar). |
One possible solution for each task. Other correct programs are fine.
{"version":1,"name":"Find a song","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},{"title":"Tidal","artist":"Rae","length":7},{"title":"Lanterns","artist":"Mo","length":3}]},{"name":"Results","table":{"fields":[{"name":"title","type":"text"},{"name":"artist","type":"text"},{"name":"length","type":"number"}]},"value":[]}],"screens":[{"id":"home","name":"Home","objects":[{"name":"Title","kind":"text","instanceVars":[],"instances":[{"id":"h1","x":24,"y":16,"w":500,"h":40,"text":"Find a song","visible":true,"vars":{}}]},{"name":"SearchInput","kind":"input","instanceVars":[],"instances":[{"id":"i1","x":24,"y":64,"w":260,"h":42,"text":"","visible":true,"vars":{}}]},{"name":"SearchButton","kind":"button","instanceVars":[],"instances":[{"id":"b1","x":296,"y":62,"w":110,"h":46,"text":"Search","visible":true,"vars":{}}]},{"name":"ShortButton","kind":"button","instanceVars":[],"instances":[{"id":"b2","x":418,"y":62,"w":160,"h":46,"text":"Short songs","visible":true,"vars":{}}]},{"name":"SortTitleButton","kind":"button","instanceVars":[],"instances":[{"id":"b3","x":590,"y":62,"w":190,"h":46,"text":"Sort by title","visible":true,"vars":{}}]},{"name":"SortLengthButton","kind":"button","instanceVars":[],"instances":[{"id":"b4","x":590,"y":114,"w":190,"h":46,"text":"Longest first","visible":true,"vars":{}}]},{"name":"AllLabel","kind":"text","instanceVars":[],"instances":[{"id":"l1","x":24,"y":116,"w":200,"h":36,"text":"All songs","visible":true,"vars":{}}]},{"name":"SongTable","kind":"table","instanceVars":[],"instances":[{"id":"T1","x":24,"y":150,"w":360,"h":300,"text":"","visible":true,"vars":{},"source":"Songs","columns":""}]},{"name":"ResultsLabel","kind":"text","instanceVars":[],"instances":[{"id":"l2","x":400,"y":170,"w":180,"h":36,"text":"Found","visible":true,"vars":{}}]},{"name":"ResultsTable","kind":"table","instanceVars":[],"instances":[{"id":"T2","x":400,"y":204,"w":380,"h":246,"text":"","visible":true,"vars":{},"source":"Results","columns":""}]},{"name":"AllButton","kind":"button","instanceVars":[],"instances":[{"id":"b5","x":400,"y":114,"w":178,"h":46,"text":"Show all","visible":true,"vars":{}}]}],"events":[{"id":"e1","else":false,"conds":[{"type":"onClicked","target":"SortTitleButton"}],"actions":[{"type":"tableSort","table":"Songs","field":"title","dir":"up"}],"children":[]},{"id":"e2","else":false,"conds":[{"type":"onClicked","target":"SortLengthButton"}],"actions":[{"type":"tableSort","table":"Songs","field":"length","dir":"down"}],"children":[]},{"id":"e3","else":false,"conds":[{"type":"onClicked","target":"SearchButton"}],"actions":[{"type":"tableClear","table":"Results"}],"children":[{"id":"e3a","else":false,"conds":[{"type":"forEachRow","table":"Songs"},{"type":"compareValues","left":"contains(lower(LoopItem.title & \" \" & LoopItem.artist), lower(SearchInput.text))","op":"=","right":"true"}],"actions":[{"type":"tableAdd","table":"Results","values":{"title":"LoopItem.title","artist":"LoopItem.artist","length":"LoopItem.length"}}],"children":[]}]},{"id":"e4","else":false,"conds":[{"type":"onClicked","target":"ShortButton"}],"actions":[{"type":"tableClear","table":"Results"}],"children":[{"id":"e4a","else":false,"conds":[{"type":"forEachRow","table":"Songs"},{"type":"compareValues","left":"LoopItem.length","op":"≤","right":"3"}],"actions":[{"type":"tableAdd","table":"Results","values":{"title":"LoopItem.title","artist":"LoopItem.artist","length":"LoopItem.length"}}],"children":[]}]}]}]}
{"version":1,"name":"Find a song","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},{"title":"Tidal","artist":"Rae","length":7},{"title":"Lanterns","artist":"Mo","length":3}]},{"name":"Results","table":{"fields":[{"name":"title","type":"text"},{"name":"artist","type":"text"},{"name":"length","type":"number"}]},"value":[]}],"screens":[{"id":"home","name":"Home","objects":[{"name":"Title","kind":"text","instanceVars":[],"instances":[{"id":"h1","x":24,"y":16,"w":500,"h":40,"text":"Find a song","visible":true,"vars":{}}]},{"name":"SearchInput","kind":"input","instanceVars":[],"instances":[{"id":"i1","x":24,"y":64,"w":260,"h":42,"text":"","visible":true,"vars":{}}]},{"name":"SearchButton","kind":"button","instanceVars":[],"instances":[{"id":"b1","x":296,"y":62,"w":110,"h":46,"text":"Search","visible":true,"vars":{}}]},{"name":"ShortButton","kind":"button","instanceVars":[],"instances":[{"id":"b2","x":418,"y":62,"w":160,"h":46,"text":"Short songs","visible":true,"vars":{}}]},{"name":"SortTitleButton","kind":"button","instanceVars":[],"instances":[{"id":"b3","x":590,"y":62,"w":190,"h":46,"text":"Sort by title","visible":true,"vars":{}}]},{"name":"SortLengthButton","kind":"button","instanceVars":[],"instances":[{"id":"b4","x":590,"y":114,"w":190,"h":46,"text":"Longest first","visible":true,"vars":{}}]},{"name":"AllLabel","kind":"text","instanceVars":[],"instances":[{"id":"l1","x":24,"y":116,"w":200,"h":36,"text":"All songs","visible":true,"vars":{}}]},{"name":"SongTable","kind":"table","instanceVars":[],"instances":[{"id":"T1","x":24,"y":150,"w":360,"h":300,"text":"","visible":true,"vars":{},"source":"Songs","columns":""}]},{"name":"ResultsLabel","kind":"text","instanceVars":[],"instances":[{"id":"l2","x":400,"y":170,"w":180,"h":36,"text":"Found","visible":true,"vars":{}}]},{"name":"ResultsTable","kind":"table","instanceVars":[],"instances":[{"id":"T2","x":400,"y":204,"w":380,"h":246,"text":"","visible":true,"vars":{},"source":"Results","columns":""}]},{"name":"AllButton","kind":"button","instanceVars":[],"instances":[{"id":"b5","x":400,"y":114,"w":178,"h":46,"text":"Show all","visible":true,"vars":{}}]}],"events":[{"id":"e1","else":false,"conds":[{"type":"onClicked","target":"SortTitleButton"}],"actions":[{"type":"tableSort","table":"Songs","field":"title","dir":"up"}],"children":[]},{"id":"e2","else":false,"conds":[{"type":"onClicked","target":"SortLengthButton"}],"actions":[{"type":"tableSort","table":"Songs","field":"length","dir":"down"}],"children":[]},{"id":"e3","else":false,"conds":[{"type":"onClicked","target":"SearchButton"}],"actions":[{"type":"tableClear","table":"Results"}],"children":[{"id":"e3a","else":false,"conds":[{"type":"forEachRow","table":"Songs"},{"type":"compareValues","left":"contains(lower(LoopItem.title), lower(SearchInput.text))","op":"=","right":"true"}],"actions":[{"type":"tableAdd","table":"Results","values":{"title":"LoopItem.title","artist":"LoopItem.artist","length":"LoopItem.length"}}],"children":[]}]},{"id":"e4","else":false,"conds":[{"type":"onClicked","target":"ShortButton"}],"actions":[{"type":"tableClear","table":"Results"}],"children":[{"id":"e4a","else":false,"conds":[{"type":"forEachRow","table":"Songs"},{"type":"compareValues","left":"LoopItem.length","op":"≤","right":"3"}],"actions":[{"type":"tableAdd","table":"Results","values":{"title":"LoopItem.title","artist":"LoopItem.artist","length":"LoopItem.length"}}],"children":[]}]},{"id":"e5","else":false,"conds":[{"type":"onClicked","target":"AllButton"}],"actions":[{"type":"tableClear","table":"Results"}],"children":[{"id":"e5a","else":false,"conds":[{"type":"forEachRow","table":"Songs"}],"actions":[{"type":"tableAdd","table":"Results","values":{"title":"LoopItem.title","artist":"LoopItem.artist","length":"LoopItem.length"}}],"children":[]}]}]}]}
{"version":1,"name":"Find a song","device":"web","features":{"level":4},"variables":[{"name":"Songs","table":{"fields":[{"name":"title","type":"text"},{"name":"artist","type":"text"},{"name":"length","type":"number"},{"name":"sound","type":"text"}]},"value":[{"title":"Blue Sky","artist":"Kai","length":3,"sound":"calm"},{"title":"Arc","artist":"Mo","length":5,"sound":"upbeat"},{"title":"Cove","artist":"Lu","length":4,"sound":"sleepy"},{"title":"Nova","artist":"Kai","length":2,"sound":"beat"},{"title":"Tidal","artist":"Rae","length":7,"sound":"upbeat"},{"title":"Lanterns","artist":"Mo","length":3,"sound":"calm"}]},{"name":"Results","table":{"fields":[{"name":"title","type":"text"},{"name":"artist","type":"text"},{"name":"length","type":"number"},{"name":"sound","type":"text"}]},"value":[]}],"screens":[{"id":"home","name":"Home","objects":[{"name":"Title","kind":"text","instanceVars":[],"instances":[{"id":"h1","x":24,"y":16,"w":500,"h":40,"text":"Find a song","visible":true,"vars":{}}]},{"name":"SearchInput","kind":"input","instanceVars":[],"instances":[{"id":"i1","x":24,"y":64,"w":260,"h":42,"text":"","visible":true,"vars":{}}]},{"name":"SearchButton","kind":"button","instanceVars":[],"instances":[{"id":"b1","x":296,"y":62,"w":110,"h":46,"text":"Search","visible":true,"vars":{}}]},{"name":"ShortButton","kind":"button","instanceVars":[],"instances":[{"id":"b2","x":418,"y":62,"w":160,"h":46,"text":"Short songs","visible":true,"vars":{}}]},{"name":"SortTitleButton","kind":"button","instanceVars":[],"instances":[{"id":"b3","x":590,"y":62,"w":190,"h":46,"text":"Sort by title","visible":true,"vars":{}}]},{"name":"SortLengthButton","kind":"button","instanceVars":[],"instances":[{"id":"b4","x":590,"y":114,"w":190,"h":46,"text":"Longest first","visible":true,"vars":{}}]},{"name":"AllLabel","kind":"text","instanceVars":[],"instances":[{"id":"l1","x":24,"y":116,"w":200,"h":36,"text":"All songs","visible":true,"vars":{}}]},{"name":"SongTable","kind":"table","instanceVars":[],"instances":[{"id":"T1","x":24,"y":150,"w":360,"h":300,"text":"","visible":true,"vars":{},"source":"Songs","columns":""}]},{"name":"ResultsLabel","kind":"text","instanceVars":[],"instances":[{"id":"l2","x":400,"y":170,"w":180,"h":36,"text":"Found","visible":true,"vars":{}}]},{"name":"ResultsTable","kind":"table","instanceVars":[],"instances":[{"id":"T2","x":400,"y":204,"w":380,"h":246,"text":"","visible":true,"vars":{},"source":"Results","columns":""}]},{"name":"AllButton","kind":"button","instanceVars":[],"instances":[{"id":"b5","x":400,"y":114,"w":178,"h":46,"text":"Show all","visible":true,"vars":{}}]},{"name":"Music","kind":"sound","instanceVars":[],"instances":[{"id":"s1","x":24,"y":462,"w":360,"h":52,"text":"","visible":true,"vars":{},"sound":"calm"}]}],"events":[{"id":"e1","else":false,"conds":[{"type":"onClicked","target":"SortTitleButton"}],"actions":[{"type":"tableSort","table":"Songs","field":"title","dir":"up"}],"children":[]},{"id":"e2","else":false,"conds":[{"type":"onClicked","target":"SortLengthButton"}],"actions":[{"type":"tableSort","table":"Songs","field":"length","dir":"down"}],"children":[]},{"id":"e3","else":false,"conds":[{"type":"onClicked","target":"SearchButton"}],"actions":[{"type":"tableClear","table":"Results"}],"children":[{"id":"e3a","else":false,"conds":[{"type":"forEachRow","table":"Songs"},{"type":"compareValues","left":"contains(lower(LoopItem.title), lower(SearchInput.text))","op":"=","right":"true"}],"actions":[{"type":"tableAdd","table":"Results","values":{"title":"LoopItem.title","artist":"LoopItem.artist","length":"LoopItem.length","sound":"LoopItem.sound"}}],"children":[]}]},{"id":"e4","else":false,"conds":[{"type":"onClicked","target":"ShortButton"}],"actions":[{"type":"tableClear","table":"Results"}],"children":[{"id":"e4a","else":false,"conds":[{"type":"forEachRow","table":"Songs"},{"type":"compareValues","left":"LoopItem.length","op":"≤","right":"3"}],"actions":[{"type":"tableAdd","table":"Results","values":{"title":"LoopItem.title","artist":"LoopItem.artist","length":"LoopItem.length","sound":"LoopItem.sound"}}],"children":[]}]},{"id":"e6","else":false,"conds":[{"type":"onItemClicked","target":"SongTable"}],"actions":[{"type":"setSoundNamed","target":"Music","name":"ClickedItem.sound"},{"type":"playSound","target":"Music"}],"children":[]}]}]}
Stretch: Search with a minimum length too: two conditions in the same sub-event.
Support: Build Search together; pairs build Short songs by changing only the test.
Describe, in steps, how to show only the books with more than 300 pages, without losing any books.
Clear a results table; for each row of Books, if pages > 300, add that row to the results table; show the results table. Books itself isn't changed.
Next: the challenge, a data app of their own.