Scratch
Intermediate
40 mins
Teacher/Student led
+85 XP

Reading and Analysing Unfamiliar Code

Read an unfamiliar Scratch program, trace it by hand to predict its output, find a planted bug, and judge an AI assistant's explanation of the code against your own analysis.

Teacher Class Feed

Load previous activity

    1 - Start: Read Code You Did Not Write ~4 mins

    Key point

    You did not write today's program, so you have to work out what it does by reading it. This is one of the most useful skills a coder has: most of the code you will ever meet was written by someone else.

    Illustration for Start: read code you did not writeYou will trace a short Scratch program by hand, work out what it prints, then find a bug hiding inside it. After that you will read an AI assistant's explanation of the same code and decide whether to trust it, check it, or reject it.

    2 - Trace It by Hand Before You Run It ~9 mins

    Here is the whole program. Read it top to bottom before you touch anything. It counts up through the numbers 1 to 5 and adds the even ones to a running total.

    Key point

    Do not click the green flag yet. On paper, keep two columns, one for number and one for total, and step through the loop five times by hand. Write down what you think the final total will be. Then run it and compare.

    when green flag clicked set [total v] to (0) set [number v] to (1) repeat (5) if <((number) mod (2)) = (0)> then change [total v] by (number) end change [number v] by (1) end say (join [Total of evens: ] (total))

    3 - Find the Planted Bug ~9 mins

    Here is a second version of the program. It is meant to count how many even numbers it finds between 1 and 5 and say the count. It runs without any error message, but the number it says is wrong.

    Your task

    Read it against what it is supposed to do. Use your debugging routine: read the symptom, find the block, form a hypothesis, test it. The variable count should end on 2, because there are two even numbers. Work out which single block is wrong and what it should be.

    when green flag clicked set [count v] to (0) set [number v] to (1) repeat (5) if <((number) mod (2)) = (1)> then change [count v] by (1) end change [number v] by (1) end say (join [Even numbers found: ] (count))

    4 - Judge the Ai's Explanation ~3 mins

    An AI assistant was asked to explain the second program, the counting one. Here is exactly what it wrote:

    Example

    "This Scratch program counts how many even numbers there are between 1 and 5. It starts count at 0 and loops five times. Each time round, it checks whether number is even, and if it is, it adds one to count. At the end it says the answer, which is 2."

    Your task

    Read the AI's explanation against the code and your own trace from the last step. Where is it right? Where is it vague? Where is it simply wrong? Decide your one-line verdict: trust, check, or reject.

    5 - Your Turn ~8 mins

    Open the counting program you traced and fix the planted bug so it correctly says how many even numbers it finds. Run it and check it says 2.

    Then write your one-line verdict on the AI's explanation. Done looks like:

    • The condition is fixed so the program says the right count.
    • You have run it and confirmed the output.
    • You have written trust, check, or reject, with one reason.
    • You can point to the exact line where the AI went wrong.

    Save your work the class way before we pull back together.

    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