Level 6

Collect and Compare

Level 6 · Chapter 6

What this lesson follows

CSTA K–12 Computer Science Standards (2017)

Data & Analysis · Grades 6–8

Collect data with a tool and clean it up to use it.

Code 2-DA-08Read the official text

Common Core State Standards for Mathematics

Statistics & Probability · Grade 6

Describe a set of data with its middle and spread.

Code 6.SP.B.5Read the official text

The short lines are our own words. We matched this lesson to these standards ourselves; the standards' owners have not reviewed or endorsed this course.

Common Core State Standards © 2010 National Governors Association Center for Best Practices and Council of Chief State School Officers. All rights reserved.

Today you will collect data from clicks, show it on monitors, and loop over the counts to find which is most.

1👋 Warm-Up

For teachers · goals · guide
Lesson Outcomes · for teachersCSTA 2
✦ CSTA 2-DA-08 · ISTE 1.5.b · Standards
🎯 I cancollect data from clicks, show it on monitors, and loop over the counts to find which is most
🧩 New blocks1 block
📝 New words5 words
⏱ Lesson time~45 min
Teacher Guide

📋 Before class

⚠️ Common misconceptions

  • Students think the count goes up by itself. It does not. Each click runs one change-by-1 block. No click, no count.
  • Students think one > test finds the most. It does not. The loop reads every item of the list and keeps the bigger number each time, so the answer in top is only final after the last item.

🎯 Differentiation

🐢 Struggling: Use only two colors and two buttons first. Put both counts in the counts list and show them with show variable. Click each button a few times, then ask: which number is bigger? Add the third color after that works.

🚀 Advanced: Keep a colors list beside the counts list. When the loop keeps a new top count, also store item (i) of [colors], so the sprite says the winning color name and not just its number.

💡 During the lesson

  • Warm-UpDo this with real hands before screens. Name three colors, have students raise a hand for one, and tally on the board. Ask: "Which color won? How do you know?" The answer — "it had the biggest number" — is the compare step they will code today. Keep it to counting and comparing; no graphing yet.
  • Try ItIn the first experiment, add puts each vote at the end of the list; insert puts it at the front, so the newest vote is on top. The second experiment keeps the list and the count together — the list grows, and the monitor number grows with it. Let students see that the list length and the count tell the same story two ways.
  • PlanTrace the comparer lane with students. The three counts are copied into one list, so the comparer never names a color again — it names positions. Start with item 1 as the top, then let the loop read item 2 and item 3 and keep the bigger number each pass. Ask what happens to the loop when a fourth color is added: length of counts becomes 4, and the same script still works. That is why the loop replaces a stack of if blocks.
  • BuildHave students trace one run on paper: i = 1, 2, 3, with the value of top written after each pass. The loop body does two jobs — compare and keep, then step i forward — and both must sit inside the repeat. Watch for the student who drops the change i by 1 at the bottom outside the C block; the loop then reads item 1 three times and the answer is wrong without any error message.