![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
lesson9-1Work in progress. -Erik Volkman1. What is a variable? A variable is named thing that lets us store data for later use. Sometimes they can be used to describe the properties of an object (length of a car, growth speed, etc.) Often a variable has a type associated with it, meaning that it can only hold only a specific kind of data (numbers, words, scripts). 2. What can we do with them? A variable can do many of the same things that a built-in property of an object can do. We can assign values to them, change the values stored in them, and test the value stored in a variable. 3. Activity: Pick an object found in the classroom and come up with some quantifiable properties of it. Use rulers, scales, your senses, and whatever else is available to you to describe this object. Example: Object: Pencil Length: 5 inches Weight: 4 grams Color: Red Text on side: "Reading jogs your mind" % Eraser Used: 50 Chewed on: Yes Mechanical: No Now find another similar object in the room, I would find another pencil, and describe the object using the properties that you came up with above. Object2: Pencil Length: 4.5 inches Weight: 5 grams Color: Black Text on side: none % Eraser Used: 90 Chewed on: No Mechanical: Yes Think about this: How does changing the value of one of the properties you described above change the object? 4. Variable Types All variables must have a type associated with them. The type tells what type of information can be stored in the variable. Typical types include integers, decimal numbers, strings (words), booleans (true or false), and colors. Using the model for the object you created above, assign types to each property, if you need a type that doesn't currently exist, create one and tell us how it is different from types that already exist. Example: Object: Pencil Length: decimal Weight: decimal Color: color Text on side: string % Eraser Used: integer Chewed on: boolean Mechanical: boolean 5. Variables in Squeak We can create variables in Squeak too. Pull up the viewer for any object in Squeak. Between the menu button and the name of the object there is a down arrow, when you click on this a box will come up asking you Link to this Page
|