Lesson 11: Traversals Practice

Overview

Students practice traversing lists, filtering and reducing lists, and using the data import tools. Along the way students develop debugging practices with traversals.

Purpose

This lesson is students primary opportunity to get hands on with lists in code prior to the Make activity in the following lesson. Give students as much class time as you can to work through these. For this lesson it's recommended that you place students in pairs as a support and to encourage discussion about the challenges or concepts they're seeing.

Agenda

Lesson Modifications

Warm Up (0 mins)

Activity (35 mins)

Wrap Up (5 mins)

View on Code Studio

Objectives

Students will be able to:

  • Write programs that use list traversals, including the filter and reduce patterns, with the support of sample code
  • Debug programs that use list traversals

Preparation

  • Review the levels that students will be completing with an eye for how you will encourage them to use the debugging practices emphasized in today's lesson.

Links

Heads Up! Please make a copy of any documents you plan to share with students.

For the Teachers

Teaching Guide

Lesson Modifications

Attention, teachers! If you are teaching virtually or in a socially-distanced classroom, please read the full lesson plan below, then click here to access the modifications.

Warm Up (0 mins)

Quick Warm Up

Teaching Tip

Move Quickly to the Activity: There's a lot in the main activity of today's lesson. You may optionally wish to do a quick vocabulary review or address any questions that came up in the last lesson. Otherwise, give students more time to get hands on with some code.

Remarks

Today we're going to have a chance to practice programming with a lot of the concepts and patterns we've explored over the last two lessons. I encourage you to go through these with a partner, but pay close attention to what each other is doing. In our next lesson you're going to have to use a lot of these on an independent project, and these activities are good practice for what you'll find there! Alright, let's get to it!

Activity (35 mins)

Practice Time

Group: It is recommended that students work in pairs for this lesson and a number of the activities feature discussion prompts. Consider using pair programming, having drivers and navigators switch every 3 minutes, not every level.

Remarks

Today you're mostly going to practice what we've learned about programming with traversals. I'm here to help you when you need. However, I first want to remind you of the following:

  • Use your debugging skills. Try to zoom in on precisely where you're getting stuck.
  • Talk to your partner! That's what they're there for!
  • Hover over blocks to read the documentation about how they work.
  • Read the resources in the Help & Tips tab
  • Talk to the group next to you. If another group asks for help make sure to take some time to talk it through with them.

We can debug traversals by using many skills that helped us with lists like using the watch panel and console.log. Another important new debugging skill will be to actually go look at your data in the Data tab. Use console.log to make sure you're successfully getting the data you want.

Teaching Tip

Providing Support: Circulate around the room through the lesson encouraging students to use the strategies introduced at the beginning of the lesson. Students have a number of supports at their fingertips, so a big part of your role is helping build their independence in using those resources.

Levels 2-4 Traversal Practice These levels have students perform simple traversals over lists that are created inside their code (not with the data import tools). In each program sample code is provided which students can use to help writing the code of their own.

  • Level 2: traverse over a list and console.log every element
  • Level 3: traverse over a list and console.log every element and its position
  • Level 4: traverse over two parallel lists and print elements from both

Levels 5-7 Reduce and Filter Practice: Students practice the reduce and filter patterns introduced in the previous lesson. In each program sample code is provided which students can use to help writing the code of their own.

  • Level 5: filter a list of students to keep only those with more than 6 letters in their names.
  • Level 6: reduce a list to find the maximum price inside of it.
  • Level 7: filter a list of countries to find those in the "Central America" region. This program makes use of the data import tools.

Levels 8 App Practice: In this level, students use the reduce pattern to finish building an app.

  • Level 8: Write code for the "reduce" pattern to calculate a student's average grade

Wrap Up (5 mins)

Synthesizing Discussion

Discussion Goal

Goal: Use this opportunity to address any lingering questions or misconceptions in the room. You can also use this as a source of discussion topics to kick off the following lesson. As you lead the discussion, call out the many resources students have access to help when they're getting stuck.

Prompt: What aspects of working with traversals do you feel like clicked today? What do you still feel like you have trouble with?

Discuss: Have students share with one another before sharing with the whole class.

Remarks

Working with traversals can be tricky. We will get more practice tomorrow by making an app that uses traversals and the data tools.


Assessment: Check For Understanding: AP Practice

Check For Understanding Question(s) and solutions can be found in each lesson on Code Studio. These questions can be used for an exit ticket.

Question: What is stored in studentScores after running the program code?

Standards Alignment

View full course alignment

CSTA K-12 Computer Science Standards (2017)

AP - Algorithms & Programming
  • 3A-AP-14 - Use lists to simplify solutions, generalizing computational problems instead of repeated use of simple variables.
  • 3B-AP-10 - Use and adapt classic algorithms to solve computational problems.

CSP2021

AAP-2 - The way statements are sequenced and combined in a program determines the computed result
AAP-2.O - For algorithms involving elements of a list: a. Represent using iterative statements to traverse a list. b. Determine the result of an algorithm with list traversals.
  • AAP-2.O.3 - The exam reference sheet providesFOR EACH item IN aList{ <block of statements>}The variable item is assigned the value of each element of aList sequentially, in order, from the first element to the last element. The code in block of statements is exe