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

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 Discussion What does the word variable mean in both mathematical and English terms?

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! You are going to build the beginning of a Scratch game.
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 Create a solid color background.
Add the text “Click on a food to eat it” to the background. Add sprites for bananas and cheesy-puffs.

8 Adding a Variable Click on “Variables”. Click on “Make a Variable”.
Name the variable “Good Nutrition Points” and set it for all sprites.

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

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

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

12 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. For extra credit, separate your 1-scene program into 3 scenes with different backgrounds: title, instructions and game itself.

13 The Good Nutrition 1 Program Rubric
Do you… Points Possible What Do You Think? Have a background with text instructions? 5 Have two food sprites, one healthy and one unhealthy? Have a variable with the name ‘Good Nutrition Points’? Have an event block with an iteration block for sprite one? 15 Have an event block with an iteration block for sprite two? Have an reinitializing event block with reinitializing iteration block? Have a 2nd healthy food sprite that iterates by +2? 20 Have a 2nd unhealthy food sprite that iterates by -3? EXTRA CREDIT Separate your 1-scene program into 3 with different backgrounds: Game title, instructions and game-playing scenes. TOTAL: 100

14 Conditionals Exploring Computer Science Lesson 4-9

15 Objectives The students will be able to:
Explain the concept of conditionals. Enhance a variable program with conditionals.

16 Discussion How would you finish a knock-knock joke when the third line begins with “If”? What are some ways we use the word “if” in English?

17 If Statements in Computing
If you have started to think about building animations like simulations and video games, then to build those more advanced programs, you will need to write code that involves decisions: If (some condition), then (do this).

18 Examples When you exit Microsoft Word, it asks you if you want to save your file. If you click “Yes”, the file is saved. If you click “No”, your changes are discarded. In a car-race simulation, the driver steers the car around curves and past mile-markers. If the car stays on the road, the score increases. If the car goes off the road into the stands, the car crashes. If the driver gets the car over the finish-line, the time is posted and the driver wins!

19 Scratch “if” Block The Scratch “if” block looks like this:
Note that only a hexagon shaped block will fit.

20 Example What does this program do?

21 Expand the Program Currently, it only does the first condition. Your task is to finish the program so that the cat will tell you the rest: If you are older than 2, “You don't need diapers." If you are older than 15, “You can drive." If you are older than 16, “You can see an R-rated movie." If you are older than 17, “You can vote." If you are older than 20, “You can gamble." If you are older than 24, “You can rent a car." If you are older than 49, “You can retire.“ Finally add: If the age is less than 3, "Sorry. You are not old enough for anything yet!"

22 Age Program Rubric Do you… Points Possible What Do You Think?
Have an age variable with slider? 10 Have a sprite saying when you don’t need diapers? (greater than 2) Have a sprite saying when you can drive? (greater than 15) Have a sprite saying when you can see an R-rated movie? (greater than 16) Have a sprite saying when you can vote? (greater than 17) Have a sprite saying when you can gamble? (greater than 20) Have a sprite saying when you can rent a car? (greater than 24) Have a sprite saying when you can retire? (greater than 49) Have a sprite saying when you’re not old enough for anything yet? (less than 3) Have proper grammar, spelling, punctuation, capitalization, etc.? EXTRA CREDIT Separate your 1-scene program into 3 with different backgrounds: Program title, instructions and age-sliding scenes. 15 TOTAL: 100

23 Enhance Your Nutrition Program
Enhance your Nutrition program by: Adding a message about being nutritious if the number of points becomes greater than 9. Adding a message about eating healthier food if the number of points becomes less than -4. A sprite can say these messages or you can use broadcast to change the sprites/stage to convey the messages. For extra credit, use both broadcast AND a sprite to convey the messages.

24 The Good Nutrition 2 Program Rubric
Do you… Points Possible What Do You Think? Have a message about being nutritious if the number of points becomes greater than 9? 30 Have a message about eating healthier food if the number of points becomes less than -4? Have a sprite saying these messages OR Have broadcast changing the stage/backdrop in order to convey these messages? (FOOD SPRITES MUST HIDE!) Have proper grammar, punctuation, spelling, capitalization, etc.? 10 EXTRA CREDIT Use both broadcast with changing stages AND a sprite to convey the messages. 15 TOTAL: 100


Download ppt "Exploring Computer Science Lesson 4-8"

Similar presentations


Ads by Google