Overview

In this lesson students work with partners to investigate several versions of the "Thermostat App" to understand how variables store and update information. To begin, students examine a version of the app where the temperature displayed changes each time a button is clicked. The next two versions of the app demonstrate how variables can store strings. Students learn about the patterns they are observing, specifically "Counter Pattern with Event" and "Variables with String Concatenation Pattern". To conclude the lesson, students review and discuss the programming patterns that they will make use of in the programs they write.

Goals

Students will be able to:

Purpose

After building a conceptual model for variables in the previous lesson, students investigate three working examples of apps that make use of variables. This lesson also introduces common programming patterns when using variables. Students will have some opportunities to modify working code in this lesson, but the most significant practice with variables will come in the following lesson.

Teaching Tip

This is the first official "Investigate" lesson in the EIPM model. Review the EIPM model in the EIPM: A Short Introduction - Resource

Investigate Lessons:

Overview: Students investigate two or three sample programs that use the new concept.

Goal: Students become comfortable reading and modifying programs that use the new concept.

A sketch showing a teacher lead students through material on a display.

Getting Started

Preview the Lesson

Remarks

Prompt: Let's do a quick review. How does a baggy represent a variable?

Discussion Goal: The baggy represents a variable by storing one item: a value on a sticky note placed in a named baggy. The value in the baggy can be changed at any time, just like a variable's value can change.

Activity

Group: Place students in pairs. One student per group should open the apps used for this lesson, beginning with Lesson2_App1.

Investigation #1: Thermostat App v.1

Open a Project: Have students open the project Lesson2_App1.

Activity: This project introduces a new app for students to investigate. It represents a Thermostat App where the temperature can be changed up and down.


Discussion Goal: Here are some points that students are likely to bring up while discussing their code:

Lines 79-80:

Lines 83-93:

Lines 95-101:


Modify: Have groups return to their original seats. Give them a couple of minutes to work on modifying the app to change the degrees by two when the up and down arrows are clicked.

Investigation #2: Thermostat App v.2

Open a Project: Have students open the project Lesson2_App2.

Activity: This program is an updated version of the Thermostat app. This time students should continue to work in partners but do not need to work with other groups. They will need to:


Discussion Goal: On line 3, the Fahrenheit temperature is converted to Celsius. Round rounds a given value to the nearest integer.


Investigation #3: Thermostat App v.3

Open a Project: Have students open the project Lesson2_App3.

Activity: This program is again an updated version of the Thermostat app with a login screen.


Discussion Goal: nameField:GetText() gets the string of text the user typed into the nameField text box. In our app, the name written in the nameField element is concatenated with "Hi" and then stored in the variable myName.


Patterns

Remarks

Display: Talk through the pattern with students.

integer counter = 0

action ButtonActivated(Button myButton)
     counter = counter + 1
end

Prompt: With a partner, discuss the following:


Discussion Goal: Students should step through each line of the pattern, explaining what's happening.

Counter Pattern with Event:

The Counter Pattern with Event might be used to update a score in a game when an item is clicked.


Remarks

Display: Talk through the pattern with students.

text myString = "rock"
text myOtherString = "roll"

text myStory = myString + " and " + myOtherString

Prompt: Explain to a partner how the "Variable with String Concatenation Pattern" works.


Wrap Up

Remarks

Prompt: Let's review. What can be stored in a variable? Why is using a meaningful name for the variable important?

Discussion Answers:

What can be stored in a variable? At this point, students should know that numbers and strings (text) can be stored in variables. Students may have also noticed that more complex data types, like Buttons or Labels, can be stored in variables as well. Students will learn more about other data types that can be stored in later lessons.

Why is using a meaningful name for the variable important? When you write code, you are not just writing for the computer, you are also writing for people. Using meaningful names help people be able to read your code easier. It also helps readers predict what values may be stored in the variables.


Journal: Add to your journal the definition for variable.

Remarks

Assessment: Check for Understanding

Question: Explain in your own words the process of creating and updating a variable. How does the Counter Pattern with Event work?

Standards Alignment