# Lesson 3: Variables Practice

## Overview

In this lesson students spend most of their time practicing using the skills and processes they have learned about variables. At the conclusion of the lesson students discuss the main things they realized and still have questions about at the conclusion of this lesson.

## Purpose

This lesson is students primary opportunity to get hands on with variables in code prior to the Make activity in the following lesson. Give students as much class time as you can to work through these. For this lesson it's recommended that you place students in pairs as a support and to encourage discussion about the challenges or concepts they're seeing. In the following lesson students are encouraged to work independently.

## Objectives

### Students will be able to:

• Write programs that use variables and expressions with the support of sample code.
• Debug programs that use variables and expressions

## Preparation

• Review the video in the level progression that covers global vs. local variables. This is a tricky topic.
• Review other programming levels to be better prepared to support students

Heads Up! Please make a copy of any documents you plan to share with students.

Forum

# Teaching Guide

## Lesson Modifications

Attention, teachers! If you are teaching virtually or in a socially-distanced classroom, please read the full lesson plan below, then click here to access the modifications.

## Warm Up (0 mins)

Teaching Tip

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

### Practice Lessons:

Overview: Students practice using the new concept through a scaffolded series of programming activities.

• Students work independently or in pairs
• Teacher introduces debugging practices that the beginning of the Activity and circulates the room during the lesson to provide targeted support.

Goal: Students gain confidence in writing and debugging programs that use the new concept.

Watch the following videos:

### Quick Warm Up

Teaching Tip

Move Quickly to the Activity: There's a lot in the main activity of today's lesson. You may optionally wish to do a quick vocabulary review or address any questions that came up in the last lesson. Otherwise, give students more time to get hands on with some code.

Remarks

Today we're going to have a chance to practice programming with a lot of the concepts and patterns we've explored over the last two lessons. I encourage you to go through these with a partner, but pay close attention to what each other is doing. In our next lesson you're going to have to use a lot of these on an independent project, and these activities are good practice for what you'll find there! Alright, let's get to it!

## Activity (40 mins)

### Practice Time

Group: It is recommended that students work in pairs for this lesson and a number of the activities feature discussion prompts. Consider using pair programming, having drivers and navigators switch every 3 minutes, not every level.

Distribute: Optionally pass out a plastic cup or other manipulative they can place on their computer when they are stuck as a signal that they need support.

Remarks

Today you're mostly going to practice what we've learned about programming with variables. As always you should be using the debugging process to help you as you work on issues.

Let's review the debugging process first. Debugging is the process of finding and fixing problems in code. We previously talked about these four steps: Describe, Hunt, Try, and Document.

Today we're going to also focus on three particular debugging skills

1. Slowing down code with the speed slider
2. Using console.log to get output
3. Using the Watch area to watch your variables change values

Teaching Tip

Providing Support: Circulate around the room through the lesson encouraging students to use the strategies introduced at the beginning of the lesson. Students have a number of supports at their fingertips, so a big part of your role is helping build their independence in using those resources.

Do This: Direct students to Code Studio, Lesson 3 Level 2.

Levels 2-3 Assigning Numbers and Strings: These levels only use the console.log() command which prints commands in the debug console. Some key points in these levels.

• Students should practice using the "Watch" area to track how variables change over a program
• Students are asked to discuss what they see with a partner
• These levels heavily reinforce language around assigning and creating variables
• Level 3 is a debugging-heavy level which introduces more rules about syntax.

Levels 4-8 Variables and Operators: These levels have students practice writing more complex expressions and using operators. A few tricky things to look out for

• These levels transition from using only `console.log` to using full apps with user interfaces.
• Level 6 introduces `\n`, the new line character
• Students continue to be encouraged to discuss what they are learning with a neighbor
• Levels 7 and 8 introduce the use of the counter pattern with numbers and strings. Students may need to consult the Help and Tips tab for support.

Teaching Tip

Reviewing a Map Level: Level 9 is a Map Level, which contains a review of variable scope. It is highly recommended that you watch the video in Level 9 prior to the lesson. Slides are available for this lesson if you would like to optinally review as a class.

Regroup: Bring the class back together to watch the Scope Practice Video.

Display: Scope Practice video. This video is located on the slides and on Level 9. You may opt to have students watch it alone or as a class.

Do This: Discuss debugging scope issues with the next three slides before directing students back to Code Studio.

Levels 9-10 Debugging Scope Issues: These levels identify a common bug that can come up when working with variables. While students should be aware of this bug, they don't quite have the background they'd need to fully understand it. For now support students in following the three main takeaways.

• Create variables once
• Create variables at the top of your program
• Don't create variables inside `onEvent()` or `function()` blocks

Level 11 Putting It All Together: This level asks students to put together many of the concepts they've seen so far. This is an opportunity to have a bit more of a "blank screen moment" while still being able to use some starter code as a guide.

## Wrap Up (5 mins)

### Synthesizing Discussion

Discussion Goal

Goal: Use this opportunity to address any lingering questions or misconceptions in the room. You can also use this as a source of discussion topics to kick off the following lesson. As you lead the discussion, call out the many resources students have access to help when they're getting stuck.

Prompt: What aspects of working with variables do you feel like clicked today? What do you still feel like you have trouble with?

Discuss: Have students share with one another before sharing with the whole class.

Remarks

Variables can be a little bit tricky, but I saw a lot of good progress today in nailing down this concept. We may have a few lingering questions, but you also have a lot of resources available. Next time you'll have a chance to put all this together by programming an app that starts with "the blank screen"!

### Assessment: Check For Understanding: AP Practice

Check For Understanding Question(s) and solutions can be found in each lesson on Code Studio. These questions can be used for an exit ticket.

Question: What will be displayed after this code segment is run?

## Standards Alignment

#### CSTA K-12 Computer Science Standards (2017)

AP - Algorithms & Programming
• 2-AP-11 - Create clearly named variables that represent different data types and perform operations on their values.

#### CSP2021

AAP-1 - To find specific solutions to generalizable problems, programmers represent and organize data in multiple ways
AAP-1.B - Determine the value of a variable as a result of an assignment.
• AAP-1.B.2 - The exam reference sheet provides the “←” operator to use for assignment. For example,a ← expression evaluates expression and then assigns the result to the variable a.
AAP-2 - The way statements are sequenced and combined in a program determines the computed result
AAP-2.C - Evaluate expressions that use arithmetic operators.
• AAP-2.C.2 - The exam reference sheet provides a MOD b, which evaluates to the remainder when a is divided by b. Assume that a is an integer greater than or equal to 0 and b is an integer greater than 0. For example, 17 MOD 5 evaluates to 2.
• AAP-2.C.3 - The exam reference sheet provides the arithmetic operators +, -, *, /, and MOD. ●       a + b●       a – b●       a * b●       a / b●       a MOD bThese are used to perform arithmetic on a and b. For example, 17 / 5 evaluates to 3.4.
AAP-3 - Programmers break down problems into smaller and more manageable pieces
AAP-3.A - For procedure calls: a. Write statements to call procedures. b. Determine the result or effect of a procedure call.`
• AAP-3.A.6 - The exam reference sheet provides the procedure DISPLAY(expression) to display the value of expression, followed by a space.
AAP-3.E - For generating random values: a. Write expressions to generate possible values. b. Evaluate expressions to determine the possible results.
• AAP-3.E.1 - The exam reference sheet provides RANDOM(a, b) which generates and returns a random integer from a to b, inclusive. Each result is equally likely to occur. For example, RANDOM(1, 3) could return 1, 2, or 3.
DAT-1 - The way that the computer represents data is different from the way that the data are interpreted and displayed for the user
DAT-1.B - Explain the consequences of using bits to represent data.
• DAT-1.B.2 - Other programming languages provide an abstraction through which the size of representable integers is limited only by the size of the computer's memory; this is the case for the language defined in the exam reference sheet.