Technical skill practice
JavaScript if...else if: Order Thresholds and Test Boundaries
An if...else if chain chooses the first satisfied branch. Put thresholds in an order that matches the classification rule, and test the exact boundary values rather than only typical inputs.
The task
Classify nonnegative integer task durations as short below fifteen minutes, standard below forty-five, and extended otherwise. Use a separate ternary only to create a compact label from an already known Boolean.
Runnable Node 22 example
const assert = require('node:assert/strict');
function band(minutes) {
if (!Number.isInteger(minutes) || minutes < 0) throw new RangeError('duration');
if (minutes < 15) return 'short';
else if (minutes < 45) return 'standard';
else return 'extended';
}
assert.equal(band(14), 'short');
assert.equal(band(15), 'standard');
assert.equal(band(44), 'standard');
assert.equal(band(45), 'extended');
assert.throws(() => band(-1), RangeError);
const ready = true;
assert.equal(ready ? 'go' : 'wait', 'go');
console.log([14, 15, 44, 45].map(band).join(','));
Expected output and explanation
Fifteen belongs to standard because the first test is strictly below fifteen. Forty-five reaches extended for the same reason. The second branch does not need to restate the lower bound: reaching it means the earlier condition already failed.
The ternary produces one value from a Boolean choice. It does not replace every multi-branch workflow, especially when nested conditions make the rule harder to read. This tutorial groups that compact expression with conditional reasoning rather than creating another page for the same classification.
Output from the example
short,standard,standard,extended
Pitfall to check
Putting the below-forty-five condition first would swallow short durations unless the branches were redesigned. Also validate the input before classification; otherwise a nonsensical value can fall through to a legitimate-looking category.
Questions, answered
Should I use nested ternaries for several thresholds?
Prefer the form that keeps the rule inspectable. A short if chain often makes ordered boundaries clearer than a deeply nested expression.
Sources and examples
ResumizeAI team. Examples are fictional teaching material, not customer results. Replace sample details with your own facts.
Your experience. A complete resume.
Build in Resumize with ATS-friendly templates, guided editing and a live preview. Start free, then upgrade when you need more.
Free account required. Free-plan PDF exports include a watermark.