Looping Over an Array With for...of

Your JavaScript report can classify one dock. Before the van leaves, the crew lead needs a count of empty docks across all five. You’ll translate the Python loop into JavaScript and count as the report visits each dock.

Loop Over the Bike Counts

The counts correspond to Elm Street, Harbor Square, Station Road, Market Hall, and Riverside Park, in that order. In Python, you’d print them with:

Language: Python
counts = [0, 14, 6, 0, 11]
for bikes in counts:
    print(bikes)

In JavaScript, a list in square brackets is called an array. Arrays get their own lesson later in this course. Replace the contents of ~/dock-report/dock-report.js with this port:

Language: JavaScript
const counts = [0, 14, 6, 0, 11];

for (const bikes of counts) {
  console.log(bikes);
}

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.