Previously, we looked at the rules for naming variables. Remember, variables are like labeled boxes for storing information.
If we write:
let player_level = 5;
Engagement Message
What value is stored inside the player_level
variable?
Let's quickly recap a key naming rule: variable names cannot contain spaces.
Engagement Message
So, if you wanted a variable for a user's age, what would you use instead of user age
?
An important thing about variables is that their values can change! However, in Rust, you need to explicitly make a variable mutable (changeable) by using the mut
keyword.
Example:
Engagement Message
What value does the level
variable hold after the third line (level = 2;
) is run?
Variables are especially useful when working with numbers because you can perform calculations with them.
Rust uses familiar symbols for math: +
for addition, -
for subtraction, *
for multiplication, and for division.
