U4Ch1L1_Variables Explore

Purpose: Students will acquire an understanding of how variables work.
Gradesheet!

Vocabulary: Variables, Values, Number, Strings, Operators, Expression, Evaluate
(Write on front board...have student take a guess.)

Activity: Log on to Code.org U4Ch1L1 _ Explore Variables

Explore Sample Apps: Ask students to play with the following 3 Apps and to be able to explain the difference between these Apps and the ones they used in Unit 3. - (The difference is that these Apps are more sophisticated. These Apps keep track of information, track information, make decisions and perform calculations!)

Activity: Variables (match students with a partner.)


1. Values – The most basic unit of data ia a value - made up of Numbers and Strings.

    1. Numbers -  Made of the digits 0 thru 9. (Yellow Sticky Note).
    2. Strings –Made of any characters found on a keyboard (excluding Numbers and Operators) – Strings in Quotes “ “. (Blue Sticky)

2. Operator –   Plus, Minus, Multiply and divide symbols.
Do This: Have students take another colored Sticky, tear it in 4 for the operators - Note "=" can be on a 4th colored Sticky.

    1. Expression -  At least two Numbers with an Operator between them.
    2. Evaluate – Carrying out the Expression (eg. 2+3=5, Evaluated the Expression)

Do This: Evaluate this Expression: 5-1 and write on Sticky?

Answer


3. Using Expressions  

    1. You can use all 4 Operators with Numbers…but, if a String is in the Expression, it may only use  .
    2. If a Number is contained in the Expression with a String, then after being Evaluated, the Number becomes a part of the String.

Do This: Evaluate the following Expressions:

 

4. Create A Variable - Think of a computer Variable as a container.

    1. Variables must follow these Rules:
      1. Must start with a letter.
      2. No quotes.
      3. No spaces.

Do This:


5. Variables & Expressions   

    1. Create a copy of the Number Sticky that is in one of the Variables (don’t take out).
    2. Create a copy of the String Sticky that is the other Variable.
    3. Create an Expression with the Variable and the Number Sticky and Evaluate.
    4. Create an Expression with the Number Sticky and the Variable Value (the one you made a copy of.) and Evaluate

Now, solve this problem:

Do This #1: Create an Expression with the Number Sticky and Variable and Evaluate.
Create an Expression with a Variable and String and Evaluate.
Create an Expression with a Variable and a Variable and Evaluate.

Now, solve this problem:


6. Lets Start Writing Programs with Variables –   Note:  <-  equals  =
Note: In math = means "are equal forever". In programming = means "put this value in this variable"

Line Number

Command To Create Variable

Variable Name

00

var

pow

Take a look at how a Variable can only have one Value.

 

Do This: Run This Program:



7. Assign a Variable with Expression  
Take a look at how you can assign values to Variables by Evaluating and Expression.




8. Assign a Variable: Expression with Variables
Do This: Run This Program:            


Do This: Run This Program: