6-8.AP.11 - Create clearly named variables that store data, and perform operations on their contents. [Algorithms & Programming (Concept) / Variables (Sub-concept) + Creating Computational Artifacts (practice)]
A variable is a container for data, and the name used for accessing the variable is called the identifier. Students declare, initialize, and update variables for storing different types of program data (e.g., text, integers) using names and naming conventions (e.g. camel case) that clearly convey the purpose of the variable, facilitate debugging, and improve readability.
As described in the Introduction to the math standards, students in 6th grade should understand the use of variables in mathematical expressions. They write expressions and equations that correspond to given situations, evaluate expressions, and use expressions and formulas to solve problems.
By the time they get to 8th grade, students should grasp the concept of a function as a rule that assigns to each input exactly one output. They understand that functions describe situations where one quantity determines another.
Science and Engineering Practice 3, Planning and Carrying out Investigations, focuses on variables as it relates to science investigations.
"From the earliest grades, students should have opportunities to carry out careful and systematic investigations, with appropriately supported prior experiences that develop their ability to observe and measure and to record data using appropriate tools and instruments.
As they become more sophisticated, students also should have opportunities not only to identify questions to be researched but also to decide what data are to be gathered, what variables should be controlled, what tools or instruments are needed to gather and record data in an appropriate format, and eventually to consider how to incorporate measurement error in analyzing data."
Most students have had some experience playing a form of video games whether it is in an arcade, on computer, on a smartphone or on a console. Within those video games, variables are abound and quite evident. Whether it is variable of number of lives, life meter, currency, mana, or ammo, students are familiar with quantities that fluctuate within a game. Students should be able to make connections to these variables and what operations are performed on them.
Students could create a counter program to keep track of the score for a basketball team. A variable (e.g. teamScore) would initially be set to zero. One button would add 1 point to teamScore for a free throw, another button would add 2 points to teamScore for a regular basket, and a third button would add 3 points to teamScore for a three-point shot.
Students could create a Rock, Paper, Scissors program. One form of input would randomize the value (1-3) of the variable (e.g. playerChoice). Then based upon the value of that variable the display would show a rock, paper, or scissors. A second variable (e.g. gameScore) would be created to keep track of the game score, where it would increment the value by 1 for a win and decrease the value by 1 for a loss.
For example, students could program a quiz game with a score variable (e.g. quizScore) that is initially set to zero and increases by increments of one each time the user answers a quiz question correctly and decreases by increments of one each time a user answers a quiz question incorrectly, resulting in a score that is either a positive or negative integer. (CA CCSS for Mathematics 6.NS.5)
Alternatively, students could write a program that prompts the user for their name, stores the user's response in a variable (e.g. userName), and uses this variable to greet the user by name.