A First Tour of JavaScript for Pythonistas (Summary)

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 const by default and let for reassignment. A const declaration 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...in visits property keys instead.
  • Define named functions with function and return, and use arrow functions for small helpers. An expression body returns automatically, while an arrow function with a braced body needs return.
  • Keep the docks in an array of objects, reading fields with dock.bikes. Use .push() to append, .length to 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.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.