The translator’s quote form needs a turnaround for Bauer Legal’s urgent 6,200-word contract and Café Linde’s 180-word menu. You can carry the Python helper’s early return into JavaScript, but forgetting an argument can lead you to promise the wrong delivery date. Start by porting the rule, then check what each call actually supplies.
Return Early From the Rush Branch
In Python, working_days(words, rush) calculates days = 2 + words // 2000, returns max(days // 2, 1) for a rush job, and otherwise returns days. The early return behaves identically in JavaScript. The function’s syntax changes because JavaScript uses braces to mark blocks instead of reading indentation.
A function declaration uses function, a name, parameters in parentheses, and a braced body. Inside it, const declares a variable you won’t reassign, and if (rush) tests whether rush is truthy, counting as true in a condition.
For the Boolean this helper expects, that test works like Python’s if rush:, though empty arrays and objects are truthy in JavaScript. JavaScript spells the Boolean values true and false. A one-line if may omit its braces, but keep them.
Port the helper and print both clients’ turnarounds with console.log():
function workingDays(words, rush) {
const days = 2 + Math.floor(words / 2000);
if (rush) {
return Math.max(Math.floor(days / 2), 1);
}
return days;
}
console.log(`Bauer Legal: ${workingDays(6200, true)} working days`);
console.log(`Café Linde: ${workingDays(180, false)} working days`);
Math.floor() rounds the quotient down, replacing Python’s //, and Math.max() selects the larger value, keeping rush turnaround at one day or more. The backtick strings insert each result at ${...}. Run the port to get:
Bauer Legal: 2 working days
Café Linde: 2 working days
For Bauer Legal, the return inside the if block exits the whole function, skipping the final return. The call for Café Linde reaches that final line. Both results match the Python rule.
Check the Calls Before the Arithmetic
Those two days depend on the call supplying the right arguments. Unlike Python, JavaScript doesn’t enforce the argument count: if an argument is omitted, its parameter receives undefined, and extra arguments have no matching parameter, so this helper ignores them.
For example, workingDays(6200) returns 5 without an error because the rush parameter is undefined, a falsy value that counts as false, so the function skips the rush branch. Pass true explicitly for Bauer Legal to restore the two-day promise. Omitting the words argument has a different result: workingDays() returns NaN, JavaScript’s not-a-number value, because undefined in arithmetic gives NaN and every later step carries it along.
Watch out for a missing return, too: reaching the end of a function produces undefined in JavaScript and None in Python. JavaScript doesn’t return its deliberately empty null value in this case. Treat undefined, or a NaN from arithmetic, in a reply as a clue that something wasn’t passed or returned. Check the call against the parameters first, then check that every required path returns a result.
You can also move the two console.log() calls above the declaration, keeping client replies at the top and helpers below. A top-level call above its def fails in Python, but a JavaScript function declaration allows this. The reason, and the rules for other function forms, come later.
In the next lesson, Returning Two Results at Once, you’ll extend the quote calculation to send back the fee and turnaround together.