Ready. Start with one instruction.
Loading the learning workspace…
FROM YOUR FIRST INSTRUCTION TO A WORKING APPLICATION
Learn JavaScript from scratch through small working examples, visual experiments and complete projects. No account or AI key required.
Predict → Experiment → Build → Test → Explain
Ready. Start with one instruction.
Loading the learning workspace…
else if lets several mutually exclusive conditions be considered in order. The first true condition wins, so more specific or higher thresholds often need to appear first. Later conditions are not evaluated after a branch is selected. This matters for grade bands or priority routing, where a broadly true condition can hide a more specific one. The example uses three clear ranges with no gaps.
const score = 6;
if (score >= 8) {
console.log("Advanced");
} else if (score >= 5) {
console.log("Ready");
} else {
console.log("Practice");
}Ready
The highest band is tested first, leaving the middle range for the second condition.
const score = 6;This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
if (score >= 8) {Choose a branch according to this condition. Only the selected path runs for this input; inspect the exact comparison and its boundary.
console.log("Advanced");Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
} else if (score >= 5) {Choose a branch according to this condition. Only the selected path runs for this input; inspect the exact comparison and its boundary.
console.log("Ready");Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
} else {Choose a branch according to this condition. Only the selected path runs for this input; inspect the exact comparison and its boundary.
console.log("Practice");Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
}Close the current instruction block.
const score = 9;
if (score >= 8) {
console.log("Advanced");
} else if (score >= 5) {
console.log("Ready");
} else {
console.log("Practice");
}Advanced
The highest band is tested first, leaving the middle range for the second condition.
const score = 9;Declare score with const. The binding cannot be reassigned. The expression after = supplies its initial value; = is assignment, not an equality comparison.
if (score >= 8) {Choose a branch according to this condition. Only the selected path runs for this input; inspect the exact comparison and its boundary.
console.log("Advanced");Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
} else if (score >= 5) {Choose a branch according to this condition. Only the selected path runs for this input; inspect the exact comparison and its boundary.
console.log("Ready");Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
} else {Choose a branch according to this condition. Only the selected path runs for this input; inspect the exact comparison and its boundary.
console.log("Practice");Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
}Close the current instruction block.
const score = 2;
if (score >= 8) {
console.log("Advanced");
} else if (score >= 5) {
console.log("Ready");
} else {
console.log("Practice");
}Practice
The highest band is tested first, leaving the middle range for the second condition.
const score = 2;This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
if (score >= 8) {Choose a branch according to this condition. Only the selected path runs for this input; inspect the exact comparison and its boundary.
console.log("Advanced");Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
} else if (score >= 5) {Choose a branch according to this condition. Only the selected path runs for this input; inspect the exact comparison and its boundary.
console.log("Ready");Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
} else {Choose a branch according to this condition. Only the selected path runs for this input; inspect the exact comparison and its boundary.
console.log("Practice");Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
}Close the current instruction block.
Repair the intentionally changed operation so the example produces the exact expected result. Then try the extension without copying the answer.
const score = 6;
if (score >= 5) {
console.log("Advanced");
} else if (score >= 5) {
console.log("Ready");
} else {
console.log("Practice");
}const score = 6;
if (score >= 8) {
console.log("Advanced");
} else if (score >= 5) {
console.log("Ready");
} else {
console.log("Practice");
}Write your ranges on paper and make sure the first condition does not swallow a later branch.
Which operation changed the result, why did it work, and what would you test next?
Use a different value that could expose a boundary or mistake. Predict the result first, run it, and explain how the concept would help in a small real application.
Related: Previous lesson Next lesson
100 lessons across 20 modules, covering variables, operators, strings, conditions, loops, functions, scope, arrays, objects, DOM, events, state, testing, asynchronous JavaScript and application development.