1 of 23

Please pick up your test.

Homework due Wed:

  • Submit image of Flowcharts from Lesson 6 bubbles 6,8 to Hub
  • Complete goFormative - U4L06 Conditional Investigate
  • Complete goFormative - U4L07 Conditionals Practice

Homework due Thurs:

  • Khan Academy readings / exercises
    • Extension on Conditional Statements lesson - due tmrw
  • 3 Conditional Statements - code and flowcharts

2 of 23

Test 2-2 Unit 4&&5 Corrections due tomorrow:

On a separate sheet of paper for each problem missed:

  • Summarize what the question in your own words
  • Write out work to show how to get to correct answer
  • Explain your misunderstanding

Take a photo of your work and then submit image/pdf on Hub.

3 of 23

Test 2-2 Unit 4&&5 KEY

Ver A

Ver B

4th per

5th per

4 of 23

To do: November 11

Simplify the following expressions:

var num = 4;

var day = "Monday";

1. num + 3 * 2

2. (num + 3) * 2

3. day == "Monday" || true && false

4. (day == "Monday" || true) && false

5 of 23

Conditional statements

A conditional statement (if statement) first evaluates a boolean expression/condition and then executes a block of code based on whether the condition evaluated to true or false.

if(boolean expression)

{

statement1;

statement2;

}

6 of 23

If statement

7 of 23

if-else syntax

if(boolean expression)

{

statement1;

statement2;

}

else

{

statement3;

}

8 of 23

Pick between 2 possibilities? If-else statement

9 of 23

if - else if statements

A chained conditional (multiple pathways) is written with if-else statements.

Exactly one section of code is executed based on the FIRST condition that evaluates to true.

10 of 23

if - else if - else statement

if(condition 1 == true)

{

condition 1 statements;

}

else if(condition 2 == true)

{

condition 2 statements;

}

else

{

if condition 1 false and condition 2 false

execute these statements;

}

11 of 23

if - else if statement

if(condition 1 == true)

{

condition 1 statements;

}

else if(condition 2 == true)

{

condition 2 statements;

}

else if(condition 3 == true)

{

condition 3 statements;

}

12 of 23

If-else if demo:

If you love dogs, stand up.

Else if you love cats, raise your hand.

Else if you love dogs and love cats, stand at front corner of room.

Else, what's wrong with you?

13 of 23

Quick Demo

Are you a cat-lover, dog-lover, or love both cats and dogs?

We must ask who loves both cats and dogs FIRST since this group is a subset of the group that loves dogs AND the group that loves cats.

The order you asks questions makes a very big difference!

Loves dogs

only

Loves cats

only

Loves

dogs & cats

Dog-lovers

Cat-lovers

14 of 23

If-else if demo: ORDER MATTERS!

If you love dogs and love cats, stand up.

Else if you love cats, raise your hand.

Else if you love dogs, stand at front corner.

Else, just sit.

15 of 23

A sequence of If statements

If you love dogs and love cats, stand up.

If you love cats, raise your hand.

If you love dogs, stand at front corner.

16 of 23

if( ....)�{� block 1�}�if(...)�{� block 2�}�if( ...)�{� block 3�}

if( ....)�{� block 1�}�else if(...)�{� block 2�}�else if( ...)�{� block 3�}

17 of 23

Unit 4 - Lesson 7

Conditionals Practice part 2

18 of 23

Unit 4 Lesson 7 - Activity

Lesson 7 Conditionals Practice:

Bubbles 4-7

Bubble 9

Write the Boolean expression that checks if money is greater than or equal to 40 and age is over 14.

19 of 23

Unit 4 Lesson 8 - Activity

Conditionals Make:

Museum Ticket Generator

Do This:

  • Navigate to Lesson 8, Bubble 1 on Code.org

20 of 23

Unit 4 Lesson 8 - Activity

Step 1 - Try the app

  • Try making tickets for different combinations of inputs.
  • Make a ticket for a weekend.
  • Make a ticket for a weekday (Monday - Friday) and someone 18 or younger.
  • Try the discount code "FREEFRIDAY" on a Friday.

Discuss:

  • What variables would you need to program this app?
  • Where does this app use conditionals (if-statements)?

21 of 23

Unit 4 Lesson 8 - Activity

Do This: Complete the U4L8 Activity Guide

Use the activity guide to plan out your code, including the variables you'll create and a flowchart of the conditional statement you'll need to write.

22 of 23

Unit 4 Lesson - Activity

Tomorrow: We'll Make the Museum Ticket Generator!

Use the activity guide to plan out your code, including the variables you'll create and a flowchart of the conditional statement you'll need to write.

Step 3 includes steps you can follow to build the app, or you can use your own process.

23 of 23

Homework

  • Complete Code.org Lesson 7 Bubble 9
  • Complete Lesson 8 Activity Guide: complete steps 1 and 2 and submit to Hub
  • Test corrections
  • Khan Academy readings / exercises
    • Extension on Conditional Statements lesson - due tmrw

Unit 4 Lesson 6 - Wrap Up