60 likes | 189 Views
Variables. Here we go. How does a computer remember things?. To make our programs remember things, we store information as “variables” Work the same way as variables in math go x = 5; x = 20; bestName = “ Guzy ”;. Computers have memory? .
E N D
Variables Here we go
How does a computer remember things? • To make our programs remember things, we store information as “variables” • Work the same way as variables in math go • x = 5; • x = 20; • bestName = “Guzy”;
Computers have memory? • Each variable stores its value in MEMORY, in a reserved spot of a specific size • Different variable types require different memory sizes • So we must DECLARE a variable to reserve the spot before we can use it to store information
Variable types • INTEGER- Integer numbers, positive AND negative. But no decimals. • STRING- Stores words, names, even novelty license plates like “1WOOO1” • CHAR- Characters, single letters, or number, or symbols. • FLOAT or DOUBLE- Decimals, take up a huge amount of space compared to integers • BOOLEAN- True or False values (more on this another time)
Special quirk of javascript • Is what we call “Loosely typed”, we make variables without stating what type they are • You can declare a variable, and give it any type later on • To declare a variable: • varmyVar; • varmyVar = “Guzy”; • varmyVar = new String;
TO DO • Declare 6 variables at the top • Make 3 of each: INTEGER, STRING in the INIT section of the code, using names and made up grades • Display on the screen using the fillText command the following: • Each name with the corresponding grade, 1 line per person • Calculate the average