Presentation is loading. Please wait.

Presentation is loading. Please wait.

Exploring Computer Science Lesson 4-8

Similar presentations


Presentation on theme: "Exploring Computer Science Lesson 4-8"— Presentation transcript:

1 Exploring Computer Science Lesson 4-8
Variables Exploring Computer Science Lesson 4-8 Please have your Journals out! Have Scratch open to a new program

2 Objectives The students will be able to:
Explain the concept of variables. Create examples of variables. Explain the concept of iteration. Create examples of iteration.

3 Write down the question.
Journal Entry What does the word variable mean in both mathematical and English terms? Write down the question. Answer with complete thoughts and sentences or you will not receive full credit on your journal

4 Variables Look at this example: x + 3 = 5 Look at this example: 2x= 12
What is the variable? What is the value of x? Look at this example: 2x= 12 Why isn’t “x” the same in both cases?

5 Variables in Programming
A variable is a name that represents a value that can be changed.

6 Open Scratch! We are going to build the beginning of your Scratch program together. The program will reward you with points when you choose a good food and take points away when you choose a bad food.

7 Add Text and Sprites Add a color to the stage.
Add “Click on a food to eat it” to the stage. Add sprites for bananas and cheesy-puffs

8 Our Variable We are going to need a variable to track our points toward good nutrition. Some place where we can keep track of the “score” We can name a variable anything we want but a good coding technique would be to make the name meaningful. What would be a good name for our variable?

9 Adding a Variable Click on “Data” Click on “Make a Variable”
Name the variable and set it for all sprites I will call mine “Good Nutrition Points”

10 Adding Nutrition Points
I want to add a point when the banana is clicked. With the Banana sprite selected add this block: Adding 1 to a variable is called iteration.

11 Subtracting Nutrition Points
I want to subtract a point when the Cheesy-puffs sprite clicked. With the Cheesy-puffs sprite selected add this block:

12 Initializing the Variable
We want the Nutrition Points to be set to zero when the game starts. Add this block to any sprite:

13 Customize Your Program!
Add a food that is worth 2 points when clicked Add a food that is -3 points when clicked Show me your program when you’re done If you are done early make the program look better or add more foods.


Download ppt "Exploring Computer Science Lesson 4-8"

Similar presentations


Ads by Google