U4Ch1L6_ Conditionals Investigate
Purpose: Students will write If/Then statements and leran how to apply them in a program.
!Note!“When” = onEvent ; “If” =The program does something "if" a boolean expression evaluates to true.
Journal:
- First: Share an example of when specific criteria has to be met in order for something to occur.
Eg. I had to turn 16, and then I was allowed to drive.
- Second: Create a Flowchart (Class Board!) for your scenario, like the last class, in which we start with a Variable, then the Expression which should include the Operator and then the outcome showing if True then one result and if False, then another result. Include Arrows. Present two values, one that will fail and one that will succeed. Example
Activity 1: Read the Provided Code and Predict the Outcome: A, B, C, D.
Video: Conditionals Part 2a - "If Statements"
Activity 2: Program Game so that it ends when the player has ‘0’ Lives.
Play the Lemon Squeeze Game.
- Group 1: Analyze lines 1-13. What does it do? Present!
- Group 2: Analyze lines 16 - 30. What does it do? Present!
- Group 3: Analyze lines 33 - 53. What does it do? Present!
Do This: Fix the game so that it ends when the player has “0” lives.
Video: Conditionals Part 2b - "If/Else Statements"
Activity 3: "Mod Operator %" - Is There An Exact Number Of Cups Or A Remainder
Play the Lemon Squeeze Game.
What is different about the end of the Game?
(When the game ends, it states on a small screen if the lemons collected is exact or has a remainder.
- All Groups: Look at lines 53-59. Discuss with a partner how the MOD operator % works. Present!
Do This: Rewrite the code.
- If the number of lemons used is a multiple of ‘5’, then the screen should state, "You collected enough lemons for an EXACT number of cups of lemon juice."
- If the number of lemons used is NOT a multiple of ‘5’, then the screen should state, “"The amount of lemons you collected does NOT make an exact number of cups of lemon juice".
- Hint: Currently, the line of code is divided by ‘2’ to determine an even/odd outcome. The change being requested is seeking the score to be divided by ‘5’ and that will determine what will now be stated. Then enter the new text shown in the lines above.
Video: Conditionals Part 2c - "If/Else If Statements"
Activity 4- “If/Else/If Statements." As the Score Increases, the Lemon Will Become Smaller .
Play The Game. What is different about the end of the Game?
(As the score increases, the lemons become smaller.)
Do This:
- Find the if-else-if statement that was added to the program.
- Draw a flowchart for the if-else-if statement. (Class Board!). Example
- Currently, the program has the lemon become smaller when the user gets more than 5 points and then 10 points.
Modify the program so that the lemon becomes really small when the user has more than 15 points.
- Now Modify your flowchart to take into account the lemon getting smaller at 5,10 & 15 points. Example
Journal: Explain why the program begins with ‘score >15’, then 10, then 5 and current size, instead of starting with the lower score that is achieved first by the user - ‘score >’5’, then 10, then 15? If you are not sure, then try it and see what happens.
Explanation of why you want to keep the "Most Specific Case" (larger number) first.
Video: Conditionals Part 3 - And & Or Operators
Activity 5: 'And' & 'Or' Operators: Add a Username and Password.
Play The Game.
What is different about the Game?
(
Must enter Username and Password in order to play.)
Do This:
- Find the if-else-if statement that was added to the program.
- Draw a flowchart for this if-else-if statement. This is not a program - use geometrice shapes, arrows and "True/False" statements. Example
- Modify the app to add one more username and password.
- Hint: Look at the current code for the Username and Password and Copy and paste it into the program. Note: You need to go to the 'Design Section / Options' and add the Username that you would like to appear in the Username dropdown window. Also, you need to make sure that what you enter in the code is what the user enters (capitals!!).