Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

CodeCombat

Introduction to Computer Science

Session 3
Variables
What did we do last time?
Warm Up Activity: Loops

Played CodeCombat CS1 levels 9-14

Level Check-in

Bonus Activity: Map Remix

2
What do you think we’ll be
doing on today’s quest?

3
Today’s Quest
Warm Up Activity: Variables

CodeCombat CS1 levels 15-18

Level Check-in

Bonus Activity: Story Builder

4
Variables

Coi
ns

5
Variables
Variables are a way for us to keep track
of information in our code, such as Variable
numbers and words.

Variable: The box is like a variable. It can hold or


store something that you can take out and use
whenever you need it.

Value: The number of coins in the box is the value


of the variable.
Value
Variable Name: You label the box to remember
Coi
what kind of value it’s storing. When you use a lot of ns
variables, you will want to use names to keep track of
them. Name

coins = 3

6
Variables
What kind of information do you need to track every day? How can they be stored as
variables?

password = “L33tCodez” teamOneScore = 6 KithgardFlightNumber = “E83”


teamTwoScore = 21

7
Story Builder

Our Variables

● age =

● name =

● song =

● food =

● number =

8
Story Builder

Our Variables
Once upon a time, there was a [age] old coder named [name].

● age = [name] liked to hum the song [song] while coding. It was so
annoying that their teammates would throw [food] until [name]
● name = would stop singing.

● song = Still, [name] was the best coder on the team and could write
[number] lines of code every day. Maybe [song] was [name]’s
● food = secret power?

● number = No one will ever know.

9
Concept Check: Variables
In this example, what part of the image is the variable, the name, and the value?

Variable
a way to store information in our program
so we can use it later

Name
we give each variable a name so we can
keep track of different ones

Pencils

Value
the information that you store inside a variable
that you can change over and over again

10
Numbers & Variables
There are different types of numbers that can be stored by variables.

2.3 4 -1.8 4 2.3

-2 36.33 100 -2 100 36.33 -1.8

-0.5574 2663 2663 -0.5574

Numbers Integers Floats


Any number A whole number that A number that has
is not a fraction or decimals
decimal
Concept Check: Types of Variables

Sort the data! Which ones are strings? Which ones are integers? Which ones are variable
names?

Strings Integers Variable Names

“1246” 3342 name

helloWorld l33t

“name”
1337
steps “Hello, world!”

“l33t” “steps”
10,423 friend
Methods with Information
Some methods return different kinds of information such as strings or numbers. You can
store that information into a variable.

enemy = hero.FindNearestEnemy()

3 You can store that string 1 The method finds the enemy
inside a variable. Now, that is nearest to the hero
enemy has the value 2

The method returns that


enemy’s name as a string.
For example: “Ursa”
Variables Video

14
Let’s get back to the dungeon!

15
Review: How to Use CodeCombat

1
4

2 5

16
Level 15

Let’s play together!

https://codecombat.com/play/level/known-enemy?

17
Independent Practice

18
Independent Practice

Log into CodeCombat


https://codecombat.com/play/dungeon

Play Levels
CS1 Levels 16-18

Bonus Activity: Story Builder


Build a story using variables! Access the activity here.

Need Help?
Always try it once before asking for help.

19
Check-In

20
What did you discover?

What I did:
-How many levels did you finish? What was your favorite level?

What I noticed:
-What did you notice as you played through the levels?
-Did you discover or learn something new?

What was challenging?


-Was something confusing about the code or the challenge?
-Do you need more practice on a specific level?

21
Quest Wrap-Up
Warm Up Activity: Variables

CodeCombat CS1 levels 15-18

Level Check-in

Bonus Activity: Story Builder

22
Any Questions?

23

You might also like