academyEX logo

Activity 7 Level 4 - Control Structures 

Repetition

In Scratch, write some code that uses repetition in various ways to navigate past various obstacles on a map. For this activity we would like you to create a remix of the following Scratch project (Unicorn and Rainbow):

Activity 7 image 1

https://scratch.mit.edu/projects/288586532/

You will see that it simply consists of a grid and contains one unicorn, one rainbow, and three palm trees.

Activity 7 image 3

For this activity you are asked to code and test a series of different algorithms in Scratch, each one taking the unicorn to the rainbow by moving one square at a time. The project starts with code that moves the unicorn to the bottom left square:

Activity 7 image 2

Each square is 30 steps apart. To move between one square and the next you will need two code blocks, one to set the direction (up, down, left or right) and one to move 30 steps. Here is one example (points to the right and moves 30 steps). In the tasks below we will refer to this pair of blocks as the ‘point and move pair’.

You can create other ‘point and move pairs’ that have different directions and/or numbers of steps.

So you can see the path taken by the unicorn, make sure that you use the ‘pen down’ block before each algorithm is executed. Also use the ‘clear’ block each time so that old pathways are erased before the new one is drawn.

In each of the tasks below, at each step we will add in some extra constraints that may require you to change your algorithm.

Algorithm 1: Move the unicorn to the rainbow in an unlimited number of moves using only the ‘point and move pairs’. There is no need to avoid the trees.

Algorithm 2:  Move the unicorn to the rainbow in an unlimited number of moves using ‘point and move pairs’ and repeat blocks. There is no need to avoid the trees.

Algorithm 3: Move the unicorn to the rainbow using no more than 10 code blocks in total. No need to avoid the trees.

Algorithm 4: Move the unicorn to the rainbow using no more than 10 code blocks in total. Avoid the trees!

Algorithm 5: Move the unicorn to the rainbow using no more than 10 code blocks in total. Avoid the trees!

Extension activity

If you want to go further you can include 'if' blocks to check if the unicorn has hit a tree or reached the rainbow. The following example shows one part of how this might be done.

Activity 7 image 4