In this lesson we will create our own calculator and program it to do addition, subtraction, multiplication and division sums. We'll also give the calculator it's own personality!
1 - Create a new Scratch project
Create a new Scratch project and delete the cat sprite.
Go to the Scratch website using the link below and click on the 'Create' link in the blue bar at the top.
By default, each new project starts with the cat sprite already added. To delete the cat click on the x in the blue circle beside the cat in the sprite list.
2 - Add the Retro Robot sprite
We're going to use a robot sprite to ask what type of sum, what numbers and also say the answer. Open the sprite library and add the Retro Robot sprite to your project.
Drag the robot to the middle of the stage area.
To add a sprite from the sprite library follow these steps:
- Put your mouse over the Choose a Sprite button
- Click on the magnifying glass
- Find the sprite you want in the library
- Click on your chosen sprite
You can use search box or the filter links (Animals, People, Fantasy etc) to locate your sprite.
3 - Add sprites for the sum types
We're going to create a sprite for each different type of sum and then program these to tell the robot what type of sum we wish to do.
To create these sprites click on the 'Paint' when adding a new sprite. This opens the sprite editor.
Follow these steps to create the addition sprite:
- Choose the colour you wish to make your sprites
- Click on the text tool (the T button) on the left hand side
- Click in the middle of the editor area
- Type +
- Click anywhere on the editor area, you will see a box appear around the +
- Use the box to increase the size of the +
- Go to your stage area and drag the new + sprite to the bottom
Repeat the above steps to create a minus sign (-), a multiplication sign (x) and a division sign (/). Line them up at the bottom of the stage area.
You can create your own sprites using the sprite editor. To create a new sprite put your mouse over the Choose a Sprite button and then click on the paintbrush.
This create a blank sprite and will open the sprite editor where you can use the tools to create your sprite. You can even create extra costumes for your sprite!
Tip: give your sprite a name so that you can recognise it in the code blocks.
4 - Create the variables
We will need to create 3 variables to help us do the sums. In the Data palette, create 3 new variables by clicking the 'Make a Variable' button.
- 'number1' this will store the first number in the sum
- 'number2' this will store the second number in the sum
- 'result' this will store the answer of the sum
When you create your first variable you will notice that new blocks for variables become available to use in the Data palette.
In the Variables palette, create a new variable by clicking the 'Make a Variable' button.
Once you click this button a box will appear asking what you want to call your variable. Give it a name that reminds you what you will be using it for. For example, if you wanted to keep track of your score in a game, you would create a variable called 'score'.
5 - Switch the robot calculator on
When the robot calculator gets switched on (using the green flag) it will introduce itself and ask what type of sum you want to do. We'll also hide the variables as we don't want them to display on the stage.
Add the following code to the Retro Robot sprite.
when green flag clicked
hide variable [number1 v]
hide variable [number2 v]
hide variable [result v]
say [Hi I'm Calco the robot, I can do sums in my head!] for (2) seconds
say [Choose which type of sum you want to do.]
This lesson is copyright of Coding Ireland. 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