Unit 4 - Lesson 6 part 1
Conditionals Investigate
To do:
Nov 4
The program above is run. Then the user clicks the "bottomButton" ONCE and then clicks the "topButton" TWO TIMES. What will be displayed in the console?
Jenny is writing a shopping app. She has created a variable to keep track of the number of items in the shopping cart. Every time someone clicks the “addItemButton”, she would like the variable to increase by 1.
What code should Jenny insert where it says <missing code> in order for her app to work?
A. cart total = 1; B. cartTotal + 1;
C. cartTotal = cartTotal +1; D. var cartTotal = cartTotal + 1;
E. var cartTotal + 1;
Unit 4 Lesson 6 - Warm Up
Flowchart Problem #1
A water park will let a visitor on a ride if they are �48 or more inches tall OR they are 14 years old or older.
In your IN, make a flowchart for this decision. Use comparison operators (<, >, ==, etc. ) and logical operators (&&, ||, !) when you write your Boolean expression.
Unit 4 Lesson 6 - Warm Up
Flowchart Problem #2
A water park will let a visitor on a ride if they are �48 or more inches tall OR they are 14 years old or older.
On IN page 46, make a flowchart for this decision. Do NOT use logical operators (&&, ||, !) when you write your Boolean expression.
Go over Homework:
Boolean Value: true or false
Boolean Expression: evaluates to either true or false
REVIEW
true
false
evaluates to
true
3
8
<
Unit 4 Lesson 6 - Activity
Unit 4 Lesson 6 - Activity
Conditional statement:
if( /* boolean expression */)
var age = 11;
if(age >= 13){
write("You can watch a PG-13 movie alone.");
}
Unit 4 Lesson 6 - Activity
Conditional statement:
if( /* boolean expression */)
var age = 11;
if(age >= 13){
write("You can watch a PG-13 movie alone.");
}
NO OUTPUT
Unit 4 Lesson 6 - Activity
Lemon Squeeze - Bubble 2
Play the game at least once. What does each section does:
Modify
Unit 4 Lesson 6 - Activity
Conditional statement:
if else
var age = 15;
if(age >= 13){
write("You can watch a PG-13 movie alone.");
}
else {
write("Not yet.");
}
Unit 4 Lesson 6 - Activity
Conditional statement:
if else
var age = 15;
if(age >= 13){
write("You can watch a PG-13 movie alone.");
}
else {
write("Not yet.");
You can watch a PG-13 movie alone.
Unit 4 Lesson 6 - Activity
Conditional statement:
if else
var age = 11;
if(age >= 13){
write("You can watch a PG-13 movie alone.");
}
else {
write("Not yet.");
}
Unit 4 Lesson 6 - Activity
Conditional statement:
if else
var age = 11;
if(age >= 13){
write("You can watch a PG-13 movie alone.");
}
else {
write("Not yet.");
}
Not yet.
Unit 4 Lesson 6 - Activity
MOD operator %
Suppose a,b are two positive integers.
a % b returns the remainder after dividing a by b.
In pseudocode, written as a MOD b
Examples:
1) 10 % 5 == 2) 12 % 5 ==
3) 14 % 2 == 4) 15 % 2 ==
5) 3 % 5 == 6) 5 % 3 ==
Homework: