A variable can be defined as a container of values.
The variable 'a' has the value 5.
The variable 'i' has the value 3.
To assign a number to variable 'a' use an assignment block:
Place a number inside the assignment block:
Slide the variable into the assignment block.
"Assigning value 2 to variable 'a'".
Slide the variable with the value 2 out of the assignment block.
Try assigning other values to variable 'a'.
The 'random' function returns a number between 1 and 6. It's like rolling a die. Use it to assign a value between 1 and 6 to variable 'a' as follows:
Place the call to the random function inside the assignment block.
Slide the variable into the assignment block.
"Calling the random function" (roll the die).
"Asigning value 4 to variable 'a' " (assign the die value to the variable).
Slide the variable with the value 4 out of the assignment block. "End of the program."
Run the program again to assign other random values to variable 'a'.
Place the blocks as follows and run the program:
As you've already learned, assign a value to variable 'a' using the assignment block:
- "Calling the random function" (roll the die), "Assigning value 6 to variable 'a'"
Then continue reading the program in the direction of the arrows.
- "Calling the 'print' function"
Print (draw) the value of variable 'a' on your whiteboard:
"End of the program".
Run the program again.