Now that we know about integer variables, we are going to use one in a computation. In this activity, we are going to create an integer variable, add 1 to it and then output the answer to our screen. The solution will use 3 lines of code. On the first line, create an integer called seconds and assign it a value of 5 to start with.
integer seconds = 5
On the next line, add 1 to seconds by assigning seconds + 1 to it. Notice we can use the variable seconds twice in the same equation (on the left and right side of the equation) because the computer will use the original value in the computer's memory in the calculation on the right side of the equation first and then write the new value into memory on the left side of the equation after the calculation is complete. So we can add one to a variable value like this:
seconds = seconds + 1
On the next line, use the output command to display the variable's value:
When you are ready, select the green Run Program button below the editor on the right (second in the tab order).
Exploration Challenge (Optional):
Output the values from 1 to 5 by incrementing the seconds variable each time and then sending the value to the console. You can do this in five separate output statements or by using a repeat loop. For more information on repeat loops in Quorum look at the Repeat Tutorial.
In the next tutorial, we will discuss Astronomy Hour of Code | Activity 0, which describes Accessible astronomy themed Hour of Code.