Locked lesson.
About this lesson
Understanding conditional statements using If, If Else, and If Else If statements.
Exercise files
Download this lesson’s related exercise files.
If and If/Else and If/Else If Statements.docx58.9 KB If and If/Else and If/Else If Statements - Solution.docx
59 KB
Quick reference
If and If/Else and If/Else If Statements
If, Else, and Else If Statements are great for testing conditions.
When to use
Any time you have a condition that you want to test, these statements are what you need.
Instructions
To create an If Statement:
if (condition) {
// do something
}
To create an If/Else statement:
if (condition) {
// do something
} else {
// do something else
}
To create an If/Else If statement.
if (condition 1) {
// do something
} else if (condition 2) {
// do somthing
} else {
// do something else
}
Hints & tips
- If statements are used to test 1 thing
- If else statements are used to test two things
- Else if statements are used to test many things
- Use logic operators inside your conditional to test and/or
Lesson notes are only available for subscribers.