Getting Started
Level 1
- 4 - Comments
- 5 - Displaying Text
- 6 - Variables - Let
- 7 - Variables - Constants
- 8 - Arithmetic Operators
- 9 - Functions
- 10 - If/Else Statements
- 11 - Comparison Operators
- 12 - If/Else Loops
- 13 - Boolean Operators
- 14 - Level 1 Complete!
Level 2
Level 3
Useful Links
Step 10 - If/Else Statements
What if we want our program to make a decision about which function it should run? This is when we use conditions! If you have a TV you can watch it in the evening. If not, you might do something else. It’s the same with code. You can give an ‘if’ condition to a machine to make a decision about what level of the code to run.
if (condition) {
do this
} else {
do something else
}
We need condition to either be true or false, so if we have something like a number we need to compare it to something.
const number = 7;
if (number >= 7) {
console.log('Our number is bigger than or equal to 7');
} else {
console.log('Our number is smaller than 7');
}