Replace vague goals with a precise question
Logical thinking is not a trick that appears after solving a large number of puzzles. Begin by describing one decision with named inputs and one observable output. The synthetic exercise below asks whether a library member may borrow another item. It is not a real library policy. The goal is to practice converting rules into code without changing their meaning.
Write the rules before the conditions
For this exercise, evaluate rules in a stated order: an inactive member is rejected; otherwise an overdue item is rejected; otherwise a member at the borrowing limit is rejected; otherwise borrowing is allowed. Ordering matters when more than one rejection condition is true because the function returns one reason. If a product owner needs every reason, that is a different output contract. Resolve that question before implementation rather than letting an accidental if-statement order decide it.
Name inputs and constraints
The function receives active, overdueCount, borrowedCount and limit. active must be a Boolean. Counts and limit are integers; counts cannot be negative and limit must be at least one. The exercise does not define dates, item categories, reservations, user identity or database updates. Listing what is outside scope prevents a small Boolean function from being mistaken for a complete authorization system.
Create a decision table
Use rows for active true/false and overdue count zero/positive. For each row, check borrowed counts below, equal to and above the limit. Predict the reason code before running the function. This exposes combinations that example-only thinking misses, such as an inactive member who also has an overdue item. The test below evaluates 12 combinations for limit three and separately checks invalid inputs.
Focus on boundary values
For a rule borrowedCount >= limit, the useful values are one below, exactly equal and above the limit. If only borrowedCount zero is tested, the most likely comparison mistake remains invisible. Apply the same technique to empty collections, first and last indexes, minimum values and time cutoffs. Boundaries are selected from the requirement; they are not random numbers.
Keep Boolean expressions actually Boolean
JavaScript logical operators return operand values, not automatically true or false in every use. This example validates active as a Boolean and uses explicit comparisons for numeric rules. That prevents strings such as yes and negative counters from quietly entering the decision. Validation belongs at a trusted boundary in a real system; repeating it everywhere can also create inconsistent rules, so decide where the contract is enforced.
Compare predictions with results
Run the test and inspect a deliberately changed condition, such as borrowedCount > limit. Confirm the equal-to-limit case then fails. Restore >= and rerun the complete table. A strong exercise includes the prediction, actual result and explanation of the mismatch. Copying a passing solution without predicting cases does not practice the reasoning step.
Extend one dimension at a time
Add one new rule, such as a temporary maintenance closure, only after writing how it interacts with all existing reasons. Update the decision table before code. If rules grow, consider returning all applicable reasons or representing a small state machine, but do not add abstraction without a concrete need. In a real application, authorization and concurrent updates require server-side enforcement and transaction design; a client-side decision helper alone is not sufficient.
Synthetic borrowing rules with explicit reason codes
export function borrowingDecision(input) {
const { active, overdueCount, borrowedCount, limit } = input;
if (typeof active !== "boolean") throw new TypeError("active must be boolean");
for (const [name, value] of Object.entries({ overdueCount, borrowedCount, limit })) {
if (!Number.isInteger(value) || value < 0) {
throw new RangeError(name + " must be a non-negative integer");
}
}
if (limit < 1) throw new RangeError("limit must be at least 1");
if (!active) return { allowed: false, reason: "INACTIVE" };
if (overdueCount > 0) return { allowed: false, reason: "OVERDUE" };
if (borrowedCount >= limit) return { allowed: false, reason: "AT_LIMIT" };
return { allowed: true, reason: "ELIGIBLE" };
}
Expected result
active=false -> INACTIVE active=true, overdueCount=1 -> OVERDUE active=true, borrowedCount=3, limit=3 -> AT_LIMIT active=true, overdueCount=0, borrowedCount=2, limit=3 -> ELIGIBLE Test output: PASS: 12 decision-table combinations, boundaries, validation, immutability and displayed-code consistency
Further reading
Check your progress
Keep your working files, test cases and notes together. Explain one design decision, demonstrate a failure case and list what you would improve next. These concrete outputs make it easier to identify the next skill to practice.