Envisioning a Computationally Enhanced Mathematics Curriculum in Hong Kong’s Primary & Secondary Schools
Mathematics problem exploration with Scratch and AI
Lesson Overview
In this lesson, students will explore how to use Scratch and AI to predict the optimal angle for solving a problem about reflection. The task involves programming a Scratch robot that rebounds upon contact with walls and obstacles, aiming to hit an insect positioned at a randomly generated x-coordinate.
Since the insect’s position changes each time, students must predict the most effective starting angle for the robot to reach the target. To complete this task, students will apply their understanding of coordinates and reflection, utilize basic Scratch programming blocks, and engage with the AI tool “Machine Learning for Kids.”
This problem-solving context encourages students to reflect on the practical value of data and AI in addressing real-life mathematical challenges.
Prior Knowledge
-
Mathematics: Fundamental concepts of Rectangular Coordinate System, basic concepts of Angles and Bearings and Definition of Reflection
-
Scratch: Moving and changing the direction of a sprite, Use of looping blocks, Programming the sprite to display messages, familiarize with using Turbo Mode
Learning Objectives
-
Understand how to use the Scratch block ‘If on edge, bounce’
-
Relate the mathematical concept of reflection to the behavior of the ‘bounce’ block in Scratch
-
Use the ‘if then’ block to make a sprite respond under specific conditions
-
Apply Machine Learning for Kids to collect data from a Scratch project and predict numerical outcomes
Mathematics & CT Outcomes
-
Mathematics:
-
Understand positive and negative values on the x- and y-axes in the rectangular coordinate system
-
Apply the concept of reflection across vertical and horizontal lines
-
-
Computational Thinking Skills:
-
Variables: Use adjustable variables (e.g., angle) within Scratch blocks
-
Loops: Implement repetition using blocks (e.g., repeat XX)
-
Conditionals: Use conditional statements (e.g., if touching insect, then say "Hit!")
-
Decomposition: Break down the movement and edge-bounce logic into smaller steps (e.g., 100-step process)
-
Lesson Details
Students will program a robot in Scratch to walk 800 steps and then stop. During its movement, the robot will bounce (simulating reflection) whenever it touches walls or obstacles, as demonstrated in the accompanying video.


Some useful blocks are provided as shown below.

An insect is now placed in the room. Based on the provided Scratch blocks and the demonstration video, students will program the robot to bounce off walls and obstacles and successfully catch the insect.
(The Scratch Remix: https://scratch.mit.edu/projects/1163660855 )

Some students may find it difficult to hit the insect. Many will realize that predicting an accurate starting angle is essential, but guessing the correct angle can be challenging and time-consuming. To address this, students will explore how AI can be used to predict the optimal angle.
Before applying AI, the class will engage in a discussion to ensure students have a basic understanding of what AI is and how it functions.
​(Link for the AI: https://machinelearningforkids.co.uk/)

By repeating the entire movement sequence 500 times, each with a randomized starting angle and insect x-coordinate, students can collect approximately 50 successful data points—instances where the robot hits the insect. These data points will be used to train the AI model.
Once trained, the AI can accurately predict the optimal angle needed to hit the insect, based on the given x-coordinate.

Guiding Questions
-
Should the robot reflect its path after completing 800 steps, or during the 800 steps? Where should the ‘if on edge, bounce’ block be placed?
-
Why might the robot fail to hit the insect? Which factors determine whether the insect can be successfully hit?
-
Why is it necessary to repeat the movement 500 times for the AI?
-
Some angles predicted by the AI do not result in a successful hit. What could be the reasons for this? How can we reduce the prediction error made by the AI?

A sample code (With My blocks preset by the teacher)
Students’ Work​

Example 1:
-
Most students successfully programmed the robot as intended. Their robots demonstrated bouncing movement by placing the ‘if on edge, bounce’ block inside a repeat loop. This allowed the robot to continuously move while simultaneously detecting and responding to collisions with edges or obstacles.

Example 2:
-
A common mistake observed was that some students placed the ‘if then’ block outside the loop. As a result, their robots failed to say “Hit!” when touching the insect. This provides a valuable teaching opportunity to explain Scratch’s execution logic: if the ‘if then’ block is placed outside the repeat loop, it will only be executed after the loop finishes. To ensure the condition is checked continuously during movement, the ‘if then’ block must be placed inside the loop.

Possible Challenges and Misconceptions
Complex Procedures in Limited Lesson Time
The procedures for using the AI tool can be complex. Given the limited lesson time (60 minutes), many students may struggle to follow the instructions without support. To prevent confusion, clear step-by-step guidance and real-time assistance from teaching staff are provided throughout the activity.
Misconceptions on the ‘Repeat’ Block
Some students have misconceptions on the ‘repeat’ block. They may either blindly put everything inside the loop or missing significant blocks outside the loop. Their robot may get some weird movement as results, for instance, sticking on the edges and passing through the obstacles.
Acknowledgement
The author would like to thank Anson Li for co-designing this lesson and appreciate all the anonymous teachers and students who participated in this research.