← Teacher guide

Two lists that must agree

Students build a playlist kept in two parallel lists, Titles and Artists, where a song's title and artist sit at the same place in each. Add puts a value on the end of both lists; clicking a title removes ClickedIndex from both. The Check shows what happens when only one list changes: every later song gets the wrong artist. This is the problem the next lesson's table solves.

Data apps · Lists that must agree · about 50 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 · Build 1–2 15 min · Check 10 min · Make it yours 15 min

Before class

This lesson uses only what App Builder apps taught (lists, List objects, ClickedIndex), at Level 3. Its point is the problem, not the solution: keep the lesson short and let the third list in Make it yours feel clumsy.

Songs and artists are made up. Students can use their own made-up songs; keep real song lyrics out.

Lists count from 1 in App Builder (ClickedIndex, item(list, 1)). Python counts from 0; that's for later.

Running the lesson

  1. Before Build 2 (whole class, on the deck): if we remove Arc from Titles only, who sang Cove? Vote, then try it.
  2. Check: draw the two lists as columns on the board, cross out one item in one column, and draw the arrows that are now wrong.
  3. Make it yours: ask what a Sort button would need to do with three lists.

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)

The bug is invisible until the second list is looked at: each list is fine on its own. Have students read the two lists side by side, row by row, after every removal.

When students get stuck

What you will seeA question to askThe fix
Nothing is added.Which event runs when Add song is clicked, and does it name both lists?Check the event's condition is AddButton is clicked, with two Add to the end of list actions.
Clicking a title does nothing.Which List's items does the event listen to?Use An item in TitleList is clicked, and Remove item ClickedIndex (not 1) from each list.
The lists are different lengths.Is there an event that changes only one list?Every add and every remove must change both lists. Press Start again to get the starting lists back.

Answers to the checks

  1. What happens to Cove?: Titles is Blue Sky, Arc, Cove. Artists is Kai, Mo, Lu. An event removes item 2 from Titles only. Who does the app now say sang Cove?
    Mo
    Cove moves up to place 2 in Titles, but Artists didn't change, so place 2 there is still Mo. Every song after the removed one now has the wrong artist.
  2. Find Nib's mistake: After Nib removes a song, the artists are wrong for every song below it. Click the line where Nib first goes wrong.
    line 2
    Line 2: Nib only removes the item from Titles. Artists keeps the old item, so every artist below it is now one place out. Both lists must lose the same place.

Solutions

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

Make it yours: a third list › Add a Lengths list

{"version":1,"name":"Two lists","device":"web","features":{"level":3},"variables":[{"name":"Titles","value":["Blue Sky","Arc","Cove"]},{"name":"Artists","value":["Kai","Mo","Lu"]},{"name":"Lengths","value":[3,5,4]}],"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":70,"w":90,"h":36,"text":"Title","visible":true,"vars":{}}]},{"name":"TitleInput","kind":"input","instanceVars":[],"instances":[{"id":"i1","x":110,"y":66,"w":200,"h":42,"text":"","visible":true,"vars":{}}]},{"name":"ArtistLabel","kind":"text","instanceVars":[],"instances":[{"id":"l2","x":330,"y":70,"w":90,"h":36,"text":"Artist","visible":true,"vars":{}}]},{"name":"ArtistInput","kind":"input","instanceVars":[],"instances":[{"id":"i2","x":410,"y":66,"w":200,"h":42,"text":"","visible":true,"vars":{}}]},{"name":"LengthLabel","kind":"text","instanceVars":[],"instances":[{"id":"l3","x":24,"y":116,"w":90,"h":36,"text":"Minutes","visible":true,"vars":{}}]},{"name":"LengthInput","kind":"input","instanceVars":[],"instances":[{"id":"i3","x":110,"y":112,"w":200,"h":42,"text":"","visible":true,"vars":{}}]},{"name":"AddButton","kind":"button","instanceVars":[],"instances":[{"id":"b1","x":630,"y":64,"w":140,"h":46,"text":"Add song","visible":true,"vars":{}}]},{"name":"Hint","kind":"text","instanceVars":[],"instances":[{"id":"t1","x":24,"y":160,"w":600,"h":30,"text":"Click a title to remove that song.","visible":true,"vars":{}}]},{"name":"TitleList","kind":"list","instanceVars":[],"instances":[{"id":"L1","x":24,"y":200,"w":240,"h":260,"text":"","visible":true,"vars":{},"source":"Titles"}]},{"name":"ArtistList","kind":"list","instanceVars":[],"instances":[{"id":"L2","x":280,"y":200,"w":240,"h":260,"text":"","visible":true,"vars":{},"source":"Artists"}]},{"name":"LengthList","kind":"list","instanceVars":[],"instances":[{"id":"L3","x":536,"y":200,"w":240,"h":260,"text":"","visible":true,"vars":{},"source":"Lengths"}]}],"events":[{"id":"e1","else":false,"conds":[{"type":"onClicked","target":"AddButton"}],"actions":[{"type":"listAdd","list":"Titles","value":"TitleInput.text"},{"type":"listAdd","list":"Artists","value":"ArtistInput.text"},{"type":"listAdd","list":"Lengths","value":"int(LengthInput.text)"}],"children":[]},{"id":"e2","else":false,"conds":[{"type":"onItemClicked","target":"TitleList"}],"actions":[{"type":"listRemoveAt","list":"Titles","index":"ClickedIndex"},{"type":"listRemoveAt","list":"Artists","index":"ClickedIndex"},{"type":"listRemoveAt","list":"Lengths","index":"ClickedIndex"}],"children":[]}]}]}

Make it yours: a third list › What about sorting?

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

Stretch and support

Stretch: Add a Sort A to Z button. With only the list actions, how close can you get, and what goes wrong? (A table, next lesson, sorts whole rows.)

Support: Build 1 together as a class; pairs do Build 2.

Exit ticket

Two lists: Names (Ana, Ben, Cy) and Scores (7, 4, 9). Ben is removed from Names only. What score does the app now show for Cy?

4: Cy moved up to place 2 in Names, and place 2 in Scores is still Ben's 4.

What each step is for

Where it leads

Next: One table instead, where each song is one row and can't be split up.