Please pick up your test.
Homework due Wed:
Homework due Thurs:
Test 2-2 Unit 4&&5 Corrections due tomorrow:
On a separate sheet of paper for each problem missed:
Take a photo of your work and then submit image/pdf on Hub.
Test 2-2 Unit 4&&5 KEY
Ver A
Ver B
4th per
5th per
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
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;
}
If statement
if-else syntax
if(boolean expression)
{
statement1;
statement2;
}
else
{
statement3;
}
Pick between 2 possibilities? If-else statement
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.
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;
}
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;
}
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?
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
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.
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.
if( ....)�{� block 1�}�if(...)�{� block 2�}�if( ...)�{� block 3�}
if( ....)�{� block 1�}�else if(...)�{� block 2�}�else if( ...)�{� block 3�}
Unit 4 - Lesson 7
Conditionals Practice part 2
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.
Unit 4 Lesson 8 - Activity
Conditionals Make:
Museum Ticket Generator
Do This:
Unit 4 Lesson 8 - Activity
Step 1 - Try the app
Discuss:
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.
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.
Homework
Unit 4 Lesson 6 - Wrap Up