Instead of printing the same message for every order, we want a decision: reject zero or negative quantities, identify quantities of five or more as bulk orders, and use a normal-order message in between.
Conditions are checked in order
const quantity = 3;
if (quantity <= 0) {
console.log('Adet pozitif olmalı.');
} else if (quantity >= 5) {
console.log('Toplu sipariş.');
} else {
console.log('Normal sipariş.');
}
The first block runs if the if condition is true. Otherwise the else-if condition is checked. If neither matches, the else block runs. Only one branch of this chain is selected. A quantity of 3 produces the normal-order message.
Try 0, then 5. Boundary values expose an important difference: >= 5 includes 5, whereas > 5 does not. Choose the operator according to the rule you actually want.
Assignment is not comparison
console.log(3 === '3');
console.log(3 == '3');
console.log(Boolean('false'));
console.log(Boolean(''));
const count = 4;
console.log(count >= 1 && count <= 10);
3 === '3' is false because the types differ. Loose equality can convert values, so 3 == '3' is true. We will normally use strict equality to avoid unplanned conversion. A single equals sign assigns a value; if (count = 4) is not asking whether count equals four.
Boolean('false') is true because the string is nonempty. JavaScript does not interpret the English meaning of the word inside the string. The empty string converts to false. A text field containing the word “false” is therefore not the same as a false boolean.
Require both conditions
count >= 1 && count <= 10 requires the value to be at least 1 and at most 10. Here && connects two required conditions. || can connect alternatives. Begin with short expressions you can read aloud rather than building a long chain immediately.
Do not copy the mathematical notation 1 <= count <= 10 into JavaScript as an interval test. It does not mean “between one and ten.” Write the two comparisons explicitly.
Two if statements are not an if/else chain
const count = 7;
if (count >= 1) {
console.log('Positive quantity');
}
if (count >= 5) {
console.log('Bulk order');
}
Both logs run because the conditions are independent. Replacing the second if with else if prevents the bulk branch after the first condition succeeds. Connection and order change behavior, not just formatting.
For mutually exclusive categories, a broad first condition can swallow a narrower one. Write the intended categories before arranging the branches.
Keep block boundaries explicit
A single statement can follow if without braces, but our examples keep braces. Adding another line should not accidentally place it outside the condition. Indentation alone does not decide what JavaScript treats as the controlled block.
Remember that assignment and comparison differ. An accidental assignment to a let binding may change the value rather than fail loudly. A const binding can expose that mistake as an error.
Test actual values, not ordinary-language meanings
console.log(Boolean(0));
console.log(Boolean('0'));
console.log(Boolean([]));
console.log(!true);
The outputs are false, true, true and false. An empty array is still truthy. To ask whether it has no elements, compare its length with zero. A string of spaces is also nonempty until you trim it.
Separate validation from classification
const raw = '5';
const cleaned = raw.trim();
const amount = Number(cleaned);
if (cleaned === '' || !Number.isInteger(amount) || amount < 1) {
console.log('Enter a positive integer.');
} else if (amount >= 5) {
console.log('Bulk order.');
} else {
console.log('Normal order.');
}
The first branch combines alternative invalid cases: empty input, a noninteger or a value below one. Only then does the program classify a valid quantity. Try an empty string, 2.5, 0, 4 and 5 and explain each selected branch.
Test more than the happy path
Run quantities 0, 1, 4 and 5, reaching all three branches. Then inspect what changes if a value becomes text. Our numeric literals are controlled examples, not already-validated user input; input checking will be a separate step when we read forms.
References: Reference 1 · Reference 2