Your crew’s dock report now runs in JavaScript. It marks Market Hall as closed, Elm Street as empty, and Harbor Square and Riverside Park as nearly full. After you complete Finish the Dock Report, it also prints the van’s collection lines and starting load of 6 bikes. You can now port a small Python program while accounting for JavaScript’s differences.
Keep the JavaScript Forms
The report’s calculations and control flow carry over from Python. These are the JavaScript forms you used to express them:
- Declare names with
constby default andletfor reassignment. Aconstdeclaration prevents reassignment, while the contents of an array or object can still change. - Build strings with backticks and
${...}expressions. Use.toFixed(0)for the report’s percentages rounded to whole numbers. - Write conditions in parentheses and bodies in braces, because indentation doesn’t define blocks. Use
else if,===,&&,||, and!. - Iterate over array values with
for...of.for...invisits property keys instead. - Define named functions with
functionandreturn, and use arrow functions for small helpers. An expression body returns automatically, while an arrow function with a braced body needsreturn. - Keep the docks in an array of objects, reading fields with
dock.bikes. Use.push()to append,.lengthto count array items, and.includes()for value membership.
Those forms let the report classify each dock, format its line, and calculate what the van needs.