Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

3. Store Variables


In this video, you’ll make a variable that stores the user’s answer to the name sprite’s question.

A variable is a container the computer uses to keep track of information it will use later.

To start, select the "name" sprite, click on the "data" menu, then click the "make a variable" button.

Name the variable something that makes sense for the sprite you selected.

In this example, it’s called "Name."

This variable will store the answer the user types when the program asks "what's your name?"

Click "OK."

To set the variable to the answer that the user types, drag out the "set Name to," block and place it under the "ask" block.

Set the variable to "answer" to make the variable store the answer the user types.

Click on the "sensing" menu, drag out the "answer" block, and place it inside the blank space of the "set name to" block.

This code stack reads: "when this sprite is clicked, ask ‘What’s your name?’ and wait until the user types an answer.

Set the variable ‘name’ to the answer that the user types."

Try it out.

Click the "name" sprite, and type in a name.

You’ll see the name you typed in both the "answer" and "name" boxes on the screen.

In this example, that’s "Aaron."

To make just one box appear on your screen, hide the "answer" box by clicking the checkbox beside the "answer" block in the sensing menu.


Now, it’s your turn: Make a variable called "name."

Add a "set variable to" block under the "ask and wait" block.

Drag out the "answer" block from the "sensing" menu, and place it in the empty space of the "set variable to" block.

Finally, remove the "answer" display from the screen by clicking the checkbox beside the "answer" block.

In the next video, you will make other variables to complete the profile page.

arrow_backward Back
Next arrow_forward
  1. Create a variable.
  2. Set the variable to the user's answer.