1 of 16

Unit 4 - Lesson 2

Variables Investigate

2 of 16

To do: October 28

On the whiteboards:

1) What are the two meanings of the + sign?

2) Write two different expressions which include a + sign for which the meanings of the + sign are different.

3 of 16

Output in Code Studio App Lab

There are two commands that allow you to print output:

1) The write() command will print output onto the app screen.

2) The console.log() command will print output in the Debug Console window.

4 of 16

Expressions

What is the output?

1) console.log("Happy " + "Halloween" );

2) console.log( 1 + 4 + "hey");

3) console.log( "hey" + 4 + 2 );

4) console.log( 1 + 4 + 2);

5) console.log("Go" + "Astros" + "!");

5 of 16

Expression: a combination of operators and values that evaluates to a single value

Variable: holds one value at a time

Assignment Operator: allows a program to change the value represented by a variable

Lesson 1 - Wrap Up

01 pow ← 1 + 2

pow

3

OR =

6 of 16

Unit 4 Lesson 2 - Activity

Variables Investigate

7 of 16

Unit 4 Lesson 2 - Activity

Lesson 2 Bubble 2

Do This:

  • Run the app
  • Predict the information that is being stored in variables

8 of 16

Unit 4 Lesson 2 - Activity

Lesson 2 Bubble 3

Do This:

  • Read Code: Read the code making sure you understand how it works.

  • Explain the code: Carefully explain lines 8-10 work in goFormative.

9 of 16

Unit 4 Lesson 2 - Activity

Adding a Watcher

10 of 16

Unit 4 Lesson 2 - Activity

Lesson 2 Bubble 3

Do This:

  • Modify: Change the degrees by two when the up and down arrow are clicked.

11 of 16

Unit 4 Lesson 2 - Activity

Lesson 2 Bubble 4

Do This:

  • Run the app.
  • Discuss changes.
  • Find all occurrences of the Math.round command.
  • Remove the Math.round and see what happens.

  • Modify: Change the code so that no space displays between the temperature and the unit descriptions ("F" or "C").

12 of 16

Unit 4 Lesson 2 - Activity

Lesson 2 Bubble 5

Do This:

  • Run the app
  • Predict the information that is being stored in variables

13 of 16

Unit 4 Lesson 2 - Activity

Lesson 2 Bubble 6

Do This:

  • Read Code: Read the code and think about what has changed and what has stayed the same.

  • Class Discussion: How does getText() work?

  • Modify: Add an explanation point "!" to the end of the string stored in userName so the following is displayed on the screen:

14 of 16

Unit 4 Lesson 2 - Activity

Counter Pattern with Event

Name

Code (Block)

Code (Text)

Counter Pattern with Event

var myVar = 0;

onEvent("id", "click", function() {

myVar = myVar + 1;

});

15 of 16

Unit 4 Lesson 2 - Activity

Variable with String Concatenation

Name

Code (Block)

Code (Text)

Variable with String Concatenation

var myString = "rock";

var myOtherString = "roll";

var myStory = myString +

" and " + myOtherString;

16 of 16

Homework

  • Complete U4L02 goFormative while completing Code.org U4L02 bubbles 1-5