Scratch
Intermediate
40 mins
Teacher/Student led
+135 XP

Reading and Analysing Unfamiliar Code

Teacher Class Feed

Load previous activity

    1 - Start: What We're Building ~4 mins

    Illustration for Start: what we're buildingToday you build a small Scratch program that adds up a team's scores, then you meet a broken copy of it. The broken one runs perfectly happily and gives the wrong answer, which is the hardest kind of bug to find.

    You will trace it by hand, fix it at your device, and then read what an AI assistant said about the same code and decide whether to believe it.

    2 - Create a New Scratch Project ~2 mins

    Go to scratch.mit.edu and click Create. Call the project Score Adder.

    You will build on the cat sprite that is already there, so there is nothing to add.

    3 - Make a List of Scores ~3 mins

    In Variables (orange), click Make a List and call it scores. Then make two variables the same way: total and count.

    Now build the start of the program. It clears the list, then adds four scores to it.

    when green flag clicked delete all of [scores v] add (3) to [scores v] add (5) to [scores v] add (2) to [scores v] add (6) to [scores v]

    4 - Add up the Scores ~4 mins

    Set total and count to 0, then use a repeat loop from Control (gold) to walk the list. Each time round it adds one score to the total and counts it.

    Read it and predict what total and count will hold at the end, before you click the green flag.

    when green flag clicked delete all of [scores v] add (3) to [scores v] add (5) to [scores v] add (2) to [scores v] add (6) to [scores v] set [total v] to (0) set [count v] to (0) repeat (length of [scores v]) change [total v] by (item (count) of [scores v]) change [count v] by (1) end

    5 - Fix the Counting Order and Run It ~3 mins

    The counter has to start at 1, because Scratch numbers list items from 1, and it must go up after the score is added. Change set count to 0 to set count to 1.

    Click the green flag. The cat should say 16, the total of 3, 5, 2 and 6.

    when green flag clicked delete all of [scores v] add (3) to [scores v] add (5) to [scores v] add (2) to [scores v] add (6) to [scores v] set [total v] to (0) set [count v] to (1) repeat (length of [scores v]) change [total v] by (item (count) of [scores v]) change [count v] by (1) end say (join [Total: ] (total)) for (3) seconds
    123learn · Online learning platform

    Unlock the full learning experience

    You're previewing this lesson. Get full access to this lesson and hundreds more — each one ready to teach, with interactive activities, printable resources and pupil progress tracking built in.

    Hundreds of curriculum-aligned lessons
    Interactive activities in every lesson
    Printable resources & progress tracking
    Copyright Notice
    This lesson is copyright of Coding Ireland 2017 - 2025. Unauthorised use, copying or distribution is not allowed.

    Scratch is developed by the Lifelong Kindergarten Group at the MIT Media Lab. It is available for free at https://scratch.mit.edu
    🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more