Lesson 3 : Conditional Logic
JavaScript 101
Time: 40+ minutes
Introduction
In this lesson, students will experiment with conditional
statements, which they can use to programmatically make
decisions based on one or more conditions or variables in the
program. The operators they learn allow them to perform
calculations and check conditions.
[Link] board&classroomId=68c680aac4fb3813c86030ea#/lessons 06/11/2025, 8 35 AM
Page 1 of 10
:
p
Commands Introduced
hasPathRight(); Returns true if there is a path to the right.
Otherwise, it returns false.
hasPathLeft(); Returns true if there is a path to the left.
Otherwise, it returns false.
isObstacle(); Returns true if the path in front has an obstacle or
storm cloud. Returns false if the path is clear.
Vocabulary
Boolean: A boolean is a data type that has only two possible
values: true or false. These two values can correspond to a lot of
meanings, such as on or off. Comparison or equality testing
statements (such as x > 4) evaluate to a boolean because x is
either greater than 4 (true) or not greater than 4 (false).If you
want to create a boolean variable named "playerAlive" to track
whether the player is alive, you could do this:
var playerAlive = true;
Conditional Statement: A conditional statement checks if a
condition is true and then only executes code if the condition is
true. Examples of conditional statements are "if" statements, "if-
else" statements, and "if-else if-else" statements. Here is what it
looks like:
"if" statement:
[Link] board&classroomId=68c680aac4fb3813c86030ea#/lessons 06/11/2025, 8 35 AM
Page 2 of 10
:
p
"if-else" statement:
"if-else if-else" statement:
Assignment Operator: Assignment operators assign a value on
the right side of the operator to the left side of the operator.
When you're using an assignment operator, it will only modify the
value on the left side of the operator. These are shortcuts for
assignments that could be written out in a slightly longer way. For
example, you can use the assignment operator *= to assign the
value of x * y to x (x *= y). However, you could also write this out
as x = x * y.
Comparison Operator: Comparison operators check the values
or expressions on the left and right side of the operator and
[Link] board&classroomId=68c680aac4fb3813c86030ea#/lessons 06/11/2025, 8 35 AM
Page 3 of 10
:
p
return a boolean value of true or false based on the comparison.
For example, you can check if x is equal to y (x == y), if x is not
equal to y (x != y), or whether x is less than y (x < y).
Logical Operator: Logical operators take one or two boolean
values and return a boolean value. For example, they can check if
both are true (&&) or if either is true (||). The logical not operator
(!) returns the opposite of a boolean value.
Nested Conditional: You can add conditionals within
conditionals. Nested conditionals can be hard to read and debug
if they are not properly documented and indented.
Objectives
Students will...
Use JavaScript commands to solve puzzle modules
Use conditionals to detect whether a condition is true and only
run code in certain cases
Use assignment operators to change the value of a variable
Use comparison operators to compare values
Use logical operators to check multiple conditions at the same
time or reverse the value of a boolean
Distinguish between assignment, comparison, and logical
operators
Materials
Computers (1 per student) with student account access to
[Link]
Warm-Up (5 minutes)
[Link] board&classroomId=68c680aac4fb3813c86030ea#/lessons 06/11/2025, 8 35 AM
Page 4 of 10
:
p
Ask students to correct the syntax or spelling error in the
following code:
1. turn_Left()
2. turnRight;
3. for(var i = 0, i < 3, i++)
4. jump
5. var var
Answers:
1. turnLeft();
2. turnRight();
3. for(var i = 0; i < 3; i++)
4. jump();
5. var
Bonus: Tell students to create at least three additional syntax
error problems.
Activities (35 minutes)
[Link] board&classroomId=68c680aac4fb3813c86030ea#/lessons 06/11/2025, 8 35 AM
Page 5 of 10
:
p
Facilitate as students complete all Conditional Logic modules on
their own:
1. What Are Conditionals? (Document)
Students will read a short document that explains conditional
statements.
Check that students are playing the "Example" sections.
Tell students to click the "I’m Done" button (located at the bottom
of the document) to move on to the next module.
2. Path Left (Puzzle)
This puzzle introduces the "hasPathLeft()" command, which
returns true if there is a path to the left. Otherwise, it returns
false.
Give a hint: Tell students to include an "if" statement.
3. Path Right (Puzzle)
This puzzle introduces the "hasPathRight()" command, which
returns true if there is a path to the right. Otherwise, it returns
false.
This puzzle module is similar to the previous one, but has a path
turning right instead of left.
4. More Turns! (Puzzle)
Students will need to use conditionals and a "for" loop to get the
airship to the treasure.
If students are struggling with the "for" loop, help them out by
providing their first line of code: for(var i = 0; i < 10; i++) {
Give a hint: Tell students to include two "if" statements.
Are students still struggling? Ask them to solve the puzzle without
conditionals or loops. Next, encourage them to collaborate with a
neighbor and incorporate conditionals and/or loops into their
[Link] board&classroomId=68c680aac4fb3813c86030ea#/lessons 06/11/2025, 8 35 AM
Page 6 of 10
:
p
solution.
5. What Are Assignment Operators? (Document)
Students will read a short document that explains assignment
operators.
Check that students are exploring the "Do It Yourself" module,
which encourages students to change the given values and
statements and observe how it evaluates.
Tell students to click the "I’m Done" button to move on to the next
module.
6. What Are Comparison Operators? (Document)
Students will read a short document that explains comparison
operators.
Check that students are exploring the "Do It Yourself" module,
which encourages students to add their own comparisons and
observe how it evaluates.
Tell students to click the "I’m Done" button to move on to the next
module.
7. What Are Logical Operators? (Document)
Students will read a short document that explains logical
operators.
Check that students are exploring the "Do It Yourself" module,
which encourages students to change the given values and see
how the output is affected.
Tell students to click the "I’m Done" button to move on to the next
module.
8. Stormy Path (Puzzle)
To solve this puzzle module, students will need to use conditional
logic to avoid the storm clouds.
Tell students that the storm clouds will appear in random
locations, so they will need to use the "if" statement to check for
[Link] board&classroomId=68c680aac4fb3813c86030ea#/lessons 06/11/2025, 8 35 AM
Page 7 of 10
:
p
storm clouds.
Remind students to use a "jump" command to make the character
jump over obstacles (e.g., storm clouds).
If students are struggling, encourage them to brainstorm possible
solutions with a partner.
9. What Is an "Else"? (Document)
Students will read a short document that explains the "else"
statement and "else-if" statement.
Check that students are playing the "Example" sections.
Tell students to click the "I’m Done" button to move on to the next
module.
10. Stormy Turns 1 (Puzzle)
To solve this puzzle module, students will need to use conditional
logic (i.e., "if" statements and "else-if" statements) to avoid the
storm clouds.
Tell students that the storm clouds will appear in random
locations, so they will need to use conditional logic to check for
storm clouds.
Are students struggling? Direct their attention to the "Hints"
section located below the coding panel.
11. Stormy Turns 2 (Puzzle)
This puzzle module is similar to the previous one, but uses the
"hasPathRight()" and "turnRight()" commands instead of the
"hasPathLeft()" and "turnLeft()" commands.
Remind students that the storm clouds will appear in random
locations, so they will need to use conditional logic to check for
storm clouds.
12. What Are Nested Ifs? (Document)
Students will read a short document that explains adding
conditionals within conditionals.
[Link] board&classroomId=68c680aac4fb3813c86030ea#/lessons 06/11/2025, 8 35 AM
Page 8 of 10
:
p
Check that students are exploring the "Example" sections.
Tell students to click the "I’m Done" button to move on to the next
module.
13. Stormy Night 1 (Puzzle)
To solve this puzzle module, students will need to use conditional
logic to avoid the storm clouds.
If students are struggling, encourage them to brainstorm with a
partner or provide part of the code for them. For example: for(var
i = 0; i < 21; i++) {
14. Stormy Night 2 (Puzzle)
Students will need to use conditional logic to avoid the storm
clouds.
Give a hint: Tell students to include two "else-if" statements.
If students are struggling, encourage them to brainstorm possible
solutions with a partner.
15. Review (Document)
Students will read a short document that reviews concepts
learned in this lesson.
Concepts include conditionals (i.e., if, else, else-if, nested ifs),
assignment operators, comparison operators, and logical
operators.
Encourage students to thoroughly read the document to help
them prepare for the quiz in the next module.
Tell students to click the "I’m Done" button to move on to the next
module.
16. Quiz (Multiple Choice)
Students will be asked 10 quiz questions to review concepts from
this lesson.
[Link] board&classroomId=68c680aac4fb3813c86030ea#/lessons 06/11/2025, 8 35 AM
Page 9 of 10
:
p
Discussion Questions/Follow-Up
Activities (20 minutes)
Review the following with your students:
How can you check if...
x is equal to y (Answer: x == y)
x is of equal value and equal type to y (Answer: x ===y)
x is not equal to y (Answer: x != y)
x is not of equal value or not equal type to y (Answer: x !== y)
x is less than y (Answer: x < y)
True or False: A nested conditional has conditionals within
conditionals. (True, and this is helpful if you want to check two
conditions)
True or False: A boolean is a data type that has only one possible
value: True. (False, a boolean is a data type that has two possible
values: True or False. These two values can correspond to a lot of
meanings, such as on or off.)
[Link] board&classroomId=68c680aac4fb3813c86030ea#/lessons 06/11/2025, 8 35 AM
Page 10 of 10
:
p