1 of 18

Unit 4 - Lesson 6 part 1

Conditionals Investigate

2 of 18

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?

3 of 18

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;

4 of 18

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.

5 of 18

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.

6 of 18

Go over Homework:

  • Complete U4L05 goFormative Conditionals Explore
  • Submit image of today's notes and truth table of boolean values written in your IN to Hub

7 of 18

8 of 18

Boolean Value: true or false

Boolean Expression: evaluates to either true or false

REVIEW

true

false

evaluates to

true

3

8

<

9 of 18

Unit 4 Lesson 6 - Activity

10 of 18

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.");

}

11 of 18

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

12 of 18

Unit 4 Lesson 6 - Activity

Lemon Squeeze - Bubble 2

Play the game at least once. What does each section does:

  • Section 1: lines 1 - 13
  • Section 2: lines 16 - 30
  • Section 3: lines 33 - 53

Modify

  • Right now the game keeps going when the player has 0 lives. Fix this problem.

13 of 18

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.");

}

14 of 18

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.

15 of 18

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.");

}

16 of 18

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.

17 of 18

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 ==

18 of 18

Homework:

  • Submit image of today's Flowchart exercises #1,2 on the Hub
  • Study for test