Search Header Logo
Variables Practice

Variables Practice

Assessment

Presentation

Computers

12th Grade

Practice Problem

Easy

Created by

Katherine Valenti

Used 5+ times

FREE Resource

19 Slides • 4 Questions

1

media
media

Unit 4 - Lesson 3
Variables Practice

Computer Science Principles

2

media

3

media

4

media

Unit 4 Lesson 3 - Activity

Debugging: the process of finding and fixing problems in code

Describe

The Problem

What do you expect it to do?

What does it actually do?
Does it always happen?

Hunt
For Bugs

Are there warnings or errors?

What did you change most recently?
Explain your code to someone else
Look for code related to the problem

Try

Solutions

Make a small change

Document

As You Go

What have you learned?

What strategies did you use?
What questions do you have?

5

media
media

Unit 4 Lesson 3 - Activity

Specific Debugging Skills for the Day

3. Use Watchers to see your
variables change values

1. Slow down code
with the speed slider

2. Use console.log to get output

6

media
media
media

Unit 4 Lesson 3 - Activity

Variables Practice

Do This:
Navigate to Lesson 3, Level 1 on Code Studio

Complete Levels 1-2

7

Assigning Numbers and Strings- Levels 1 & 2

  • Practice using the Watch area to track how variables change over a program

  • Reinforce language about assigning and creating variables

  • Level 2 is debugging heavy

    • Introduces more rules on syntax

8

media
media
media

Unit 4 Lesson 3 - Activity

Variables Practice

Do This:

Complete Levels 3-7

9

Variables & Operators- Levels 3 - 7

  • Transitions from using only console.log to full apps with user interfaces

  • Level 5 introduces \n the new line character

  • Levels 6 and 7 introduce the use of the counter pattern with numbers and strings

    • May need to consult the Help and Tips tab for support

10

media

Unit 4 Lesson 3 - Activity

11

media

Unit 4 Lesson 3 - Activity

When you create variables you should:

twice and this can cause errors.

Create your variables outside any function or

onEvent() blocks.

Outside Functions or onEvent()

media

12

media
media
media

Unit 4 Lesson 3 - Activity

There's two types of variables, global and local, and so far we've only used global
variables. Here's the main difference between global and local variables.

Global vs. Local Variables

Type of
Variable

How It Works

How Created

Picture

Global

var used
outside an
onEvent()

Local

var used
inside an
onEvent()

Permanent. Can be used
anywhere in your code.

media

13

media
media

Unit 4 Lesson 3 - Activity

This code is pretty confusing. While it looks like there's only one variable being used, it actually has two variables, one local and one global, and they're both named count! Changing the value on one will have no impact on the other. This can cause unexpected behavior in your code and it can get tricky to debug.

Avoiding Local Variables and Debugging

media
media

14

media
media
media

Unit 4 Lesson 3 - Activity

Variables Practice

Do This

Complete Levels 8-9

15

Debugging Scope Issues- Levels 8 & 9

  • Identify a common bug that can come up when working with variables.

    • Create variables once

    • Create variables at the top of your program

    • Don't create variables inside onEvent() or function() blocks

16

media
media
media

Unit 4 Lesson 3 - Activity

Variables Practice

Do This

Complete ALL choice levels in Module 10

17

Putting It all Together- Level 10

  • Level 10a: - Use code from one button to make others work

  • Level 10b: - Add code to keep track of different variables depending on the event

  • Level 10c: - Practice using string concatenation to add captions to a photo

18

Open Ended

Pick a variable in your code from any of the modules. What is the purpose of that variable in that particular program?

19

media

20

Open Ended

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

21

Reference Sheet

  • The AP Reference Sheet shows how variable assignment questions will be represented on the exam.

media

22

Multiple Choice

Question image

What will be displayed after this code segment is run?

1

2

2

5

3

6

4

8

23

Multiple Choice

Question image

The program below is run. Which of the following COULD NOT possibly be the output from that program?

1

1

1

20

20

2

2

2

11

11

3

10

10

10

10

4

10

5

10

5

media
media

Unit 4 - Lesson 3
Variables Practice

Computer Science Principles

Show answer

Auto Play

Slide 1 / 23

SLIDE