Lesson 4 of 15 · about 14 minutes · if / else if / else, comparisons, && and ||.
⚡ 0 XP
Step 1 of 2
if, else if, else
Programs make choices with if. JavaScript checks each condition from top to bottom and runs the first block whose condition is true:
if (marks >= 90) { ... }
else if (marks >= 75) { ... }
else { ... } runs when nothing above was true
Comparison operators: ><>=<=, === (equal) and !== (not equal). Always use three equals === to compare.
In this challenge your code sits inside a small functiongradeFor(marks) so we can test it with many marks. return sends the answer back. You will learn functions fully in Unit 4.
Programs make choices with if. JavaScript checks each condition from top to bottom and runs the first block whose condition is true:
if (marks >= 90) { ... }
else if (marks >= 75) { ... }
else { ... } runs when nothing above was true
Comparison operators: ><>=<=, === (equal) and !== (not equal). Always use three equals === to compare.
In this challenge your code sits inside a small functiongradeFor(marks) so we can test it with many marks. return sends the answer back. You will learn functions fully in Unit 4.