Practice Your answers and score aren't saved. Back to the activity

Variables: Storing and Changing a Value

Directions

A variable is a name that stores a value, like a labeled box that holds one thing at a time. In these steps, "Set" replaces whatever value a variable was holding, and each step changes only the variable it names. Work through the steps in order, one at a time.

Question 1 of 8Answered

A soccer video game keeps track of a player's score during a match by running these steps in order.

  1. Set score to 5.
  2. Add 3 to score.
  3. Multiply score by 4.

What is the value of score after step 3 has finished?

Enter a number.

Question 2 of 8Answered

Rory wrote a savings program that tracks the money in his piggy bank, and it runs these steps in order.

  1. Set savings to 12.
  2. Set savings to 4.
  3. Add 6 to savings.

What is the value of savings after step 3 has finished?

Enter a number.

Question 3 of 8Answered

A gardening program tracks the height of a hedge as it grows and then gets trimmed.

  1. Set height to 20.
  2. Add 15 to height.
  3. Subtract 8 from height.
  4. Double height.

What is the value of height right after step 3, before step 4 runs?

Enter a number.

Question 4 of 8Answered

These steps use two variables named original and backup. The step "Set backup to original" gives backup the value that original has at that moment.

  1. Set original to 7.
  2. Set backup to original.
  3. Add 5 to original.

What is the value of backup after step 3 has finished?

Enter a number.

Question 5 of 8Answered

A variable can store words as well as numbers. Follow these steps from a word-building game.

  1. Set word to "rain".
  2. Set word to word followed by "bow".

What is stored in word after step 2?

Choose one answer.

Question 6 of 8Answered

Dina's program stores 3 in a variable named first and 8 in a variable named second. She wants to swap them, so that first ends at 8 and second ends at 3. Which steps do that?

Choose one answer.

Question 7 of 8Answered

A hiking app keeps track of how far a hiker has walked on a trail and how much of the trail is left.

  1. Set trail to 10.
  2. Set hiked to 3.
  3. Set remaining to trail − hiked.
  4. Set hiked to hiked + remaining.

What is the value of hiked after step 4 has finished?

Enter a number.

Question 8 of 8Answered

A school supply program counts the pencils and markers in a classroom bin by running these steps in order.

  1. Set pencils to 4.
  2. Set markers to pencils + 6.
  3. Set pencils to markers × 2.
  4. Set markers to markers + pencils.

What is the value of markers after step 4 has finished?

Enter a number.

All done? Finish.

8 questions are not answered yet. Pick a number to go back to it.

Finish to see your score and every answer.

0 of 8 answered