Please enable JavaScript to use CodeHS

California Computer Science

Lesson 3.12 If/Else Statements

Description

In this lesson, students learn about an additional control structure, if/else statements. If/else statements let students do one thing if a condition is true, and something else otherwise.

if/else statements are written like this:

if(frontIsClear())
 {
      // code to execute if front is clear
 }
 else
 {
      // code to execute otherwise
 }

Objective

Students will be able to:

  • Explain the purpose of an If/Else statement
  • Create If/Else statements to solve new types of problems
  • Identify when it is appropriate to use an If/Else statement