Modify your code
Starting from Scratch - Lesson 3
Objectives
- Use logic to debug existing code and explain your changes.
- Modify existing code for a particular purpose and explain your changes.
Lesson 1 - Define and predict
Lesson 2 - Reading code
Lesson 3 - Modify your code
Lesson 4 - Sequencing and repetition
Lesson 5 - Plan your make
Lesson 6 - Review and refine
Before the lesson
In this lesson there is another activity for the students to complete that is based in Purple Mash. If you do not have access to Purple Mash a PDF version is also available as a printable worksheet.
If using Purple Mash, before the lesson:
- Open this link,
- Download the entire file contents by clicking the download arrow in the top right of the screen.
- Upload it to your own 'Work' area in Purple Mash,
- Set it as a 2Do for your class so they can access it during the lesson.
See lesson 2 if you need more detailed instructions on how to do this.
Introduction
In the last lesson, students progressed on to reading code from Scratch. Begin by recapping some of the key learning about Scratch.
- What is a sprite? - any character or object on the screen that can be individually programmed.
- What colour blocks make the sprites move? - Dark blue
- What different Event blocks did we see being used to start the programs? - Clicking the green flag button, clicking the sprite, pressing a key on the keyboard.
- What is a coordinate and how can they be used in Scratch? - They are numbers that represent a sprite's horizontal and vertical position on the X and Y axis, and therefore their position on the screen. They can be used in Scratch to set or change a sprite's position and create movement.
In this lesson, we are going to continue our journey through the PRIMM model of learning and focus on the students investigating and modifying code that is given to them. This transfers the ownership of the code from being not theirs to partly theirs and should develop their confidence as they extend the function of the code.
- Predict
- Run
- Investigate
- Modify
- Make
Main tasks
Debugging
Begin with a debugging challenge for the students. They are provided with a Scratch Project and code. They must read the description on the activity sheet of what should happen in the program (the yellow box), and consider if the code is correct. They should then attempt to describe the changes they would make. There is a panel on the left of the screen that shows things for them to include in their answer.
They can view and experiment with the actual Scratch project to help them understand the errors in the code and correct it. They can access it with the short URL at the bottom of the worksheet. Please note that this is not a live link, they will need to open another browser tab and type the URL into the address bar, then press Enter/Return.
You can find a solution version of the Scratch project HERE.
The changes made to the code are:
- The 'when green flag is clicked' block is swapped for 'when space key is pressed' block
- The 'go to x y' block has coordinates that make sure the ball starts on Avery's hand, as it was previously beginning with Jordyn.
- The two sets of 'glide to x y' blocks have been swapped over, so the movement goes from Avery to Jordyn and back again. It was previously the opposite.
- The number in the counted loop has been changed to 4 so the sequence is repeated 4 times. It was previously only 2.
Finish this activity by asking the students to explain the changes they made and why they made them.
Modifying code
Ask the children to open a new empty Scratch project at scratch.mit.edu. Give them a paper copy of Lesson 3 - Modify your code.
Here they have two of the three programs from last week's reading code activity that they completed in Purple Mash, plus a new program (No.3). In each case, they must build the code provided as a starting point but then modify the code by making their own changes. They can change:
- numbers or words that are editable in blocks,
- the order of the blocks
- the actual blocks for others or add new blocks entirely.
Once they are happy with their changes they should complete the sheet and describe the changes they have made and the effect the changes had when they ran their program.
Then they should share one of the changes they made with a partner before moving on to the next part of the activity.
At the end of the lesson ask the students to save their work. If they are logged in with school Scratch accounts you can ask them to share their work to a class studio you create to 'collect' their work. If they are not logged in or are using the desktop version, they could save to their computer, either directly into a folder in your shared area, or into downloads, and then copy and paste the file to a shared area.
Plenary
Open a couple of examples of work from the students on the big screen if possible. Ask them to explain the changes they made in the modifying activity and then ask the rest of the class to read the new code and predict what effect the changes will have. Then run the code and compare their answers to the reality.
If you are not able to display a student's project. Show the same starting code they were given in a Scratch project of your own and ask them to suggest some of the changes they have made. Model those changes on the big screen and ask students to predict what effect the changes will have, before running the code and comparing their answers to the reality.