This activity has two parts:
- in Part 1, you will be introduced to variables through the creation of an Addition Program;
- in Part 2, you will be introduced to conditional statements through the creation of an Addition Game.
Part 1 – Creating an Addition Program in Scratch
For this task, you will follow instructions in a video tutorial to create an Addition Program in Scratch that incorporates variables.
A Variable is kind of like a container – it holds information, and as the name suggests (varies is the root word), this information may change throughout the program. In a basketball game for example, the total points for each team is stored in a variable that can be displayed on a scoreboard. In a video game, variables are used to keep track of users’ scores.
Go ahead and follow the video tutorial instructions to create this application in Scratch. You will start by clicking on Create when you get to the Scratch website.
Once you have finished following along with the video to create your program, answer the following three questions and then move onto the two extension tasks:
Questions
- What are the names of the three variables used in this program?
- What information does each of these variables contain?
- Does the order of the lines of code matter?
Extensions
- Change the application to a Multiplication Program. The symbol * means to multiply in the coding world. Remember to change the name of your sum variable to what the answer is called in a multiplication statement.
- Add a third variable called num3 and make it so the user will enter in three numbers, rather than 2, and then the program will multiply them together.
Part 2 – Creating a simple Addition Game in Scratch
For this task, you will follow instructions in a video tutorial to create an Addition Game in Scratch that incorporates variables and conditional statements.
A Conditional Statement can be used to help a program to make a decision.
A Conditional Statement is a type of coding instruction used to compare values and express and make decisions. A conditional statement tells a program to execute an action depending on whether a condition is true or false. It is often represented as an if-then or if-then-else statement.
For our Addition Game that you are about to make, the user will be presented with two numbers and they will be asked to provide the sum of the two numbers. A conditional statement will be used to compare the user’s answer to the correct sum and will tell the user if they are correct or incorrect.
Below you will see the pseudocode for the conditional statement in this program:
Pseudocode is an informal way of describing a computer program or algorithm that is an intermediary between everyday language and programming code. Pseudocode is often used before actual coding to explain the design process in a less technical way.
Go ahead and follow the video tutorial instructions to create this application in Scratch. You will start by clicking on Create when you get to the Scratch website.
Once you have finished following along with the video to create your program, answer the following four questions and then move onto the extension tasks:
Questions
- What are the names of the four variables used in this program?
- What information does each of these variables contain?
- What is the range of random numbers that num1 and num2 might be?
- Based on the current range for num1 and num2 variables, what is the lowest and highest number that the sum variable value can be?
Extensions:
- Change this game to a multiplication game.
- Alter the code so that the range for the variable values of num1 and num2 is between 0 and 100.
- Add a repeat so that once the user answers, new numbers appear.
- Add a new variable to keep track of the number of correct answers.
- Add two more variables so that you can keep track of the number of questions, correct answers and percentage answered correctly. Display this information to the user by displaying the variables.
- Write pseudocode for a program that does the following:
- Asks the user their age
- Tells them whether they are old enough to vote
Your teacher can provide you with the solutions if you get stuck.