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!
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.
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:
You can use search box or the filter links (Animals, People, Fantasy etc) to locate your sprite.
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:
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.
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.
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'.
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.]