« Back to Main Page

Beginner Variables

From Bold Idea Knowledgebase

Introduction

A variable is like a jar. We can store anything inside of it, and we can give it a label so that we know what’s inside. What we put inside the jar is called a value. For example, this cookie jar is a variable, and the value it contains is chocolate chip cookies – yum! We gave the jar a label – cookie – so that we remember the value it contains.

V Intro - Cookie Jar.png

In coding, we use variables to store data while we run our programs. In a video game, for example, a variable called Score can contain a number that represents how many points the player has earned. This ‘Hike and Seek’ game in Scratch includes a way to track points when the user clicks on a bear – plus, it tracks when the user doesn’t click on the bear before it hides.

V Intro - Hike and Seek.png

What is it?

A variable is a placeholder for a piece of information that can change.

Activities

Keep Score in Scratch.

Make your own simple game in Scratch that keeps a score. Create a new Scratch project and under the ‘Scripts’ tab, click on ‘Data.’ From there, click on the ‘Make a Variable’ button. Make up a label for the variable next to ‘Variable Name’ and click ‘OK.’ Did you notice all the new blocks that were created?

Follow the instructions below to create a simple share-eats-fish game with a scoring component.

V Keep Score - Fish.png

Pong Game in Scratch.

Did you know that Pong was the first ever arcade game? It’s actually a bit like tennis with two paddles that bounce the ball from one side of the screen to the other. Work in pairs to create your own Pong game using the step-by-step tutorial in Scratch. When you’re done, work with a partner to locate all of the times you used a Loop, a Conditional statement and a Variable in your code blocks.