Astronomy Hour of Code

Activity 5: Create an integer variable


As we just learned variables are containers in the memory of a computer to hold values. There are different types of containers though to hold different types of values. We already learned about text variables, but there are other kinds of variables as well. In this activity, we are going to learn how to create an integer variable which can be used to hold a numeric value. An integer is any number which is positive or negative, including zero which does not have any decimal places. Variables types like integer that can hold numeric values are important in computers because we use them to calculate formulas and to change values. Later we will learn about numeric values that have decimal places and about how to you can change the type of a variable in some cases.

One of the things astronomers need to communicate to a robotic telescope is how long to take an image. In Skynet, we specify this time in the number of seconds. For the next activity, let's create an integer variable called seconds and assign it a value of 5, like this:

integer seconds = 5

On the final line, use the output command to display the variable's value:

output seconds

When you are ready, select the green Run Program button below the editor on the right (second in the tab order).

Exploration Challenge (Optional):

In the previous Exploration Challenges, we have added text variables and strings in quotations in the output line. We can also mix different types of variables in output statements as well as use more than two variables in the same line. For this challenge, create two more integer variables called hours and minutes and assign values to them like you did with seconds in this activity. In the output line, use the variables and text strings with colons (":") to output them in a typical time format like: 1:48:23.

Next Tutorial

In the next tutorial, we will discuss Astronomy Hour of Code | Activity 0, which describes Accessible astronomy themed Hour of Code.