Loading video player…

Welcome to the Night-Bus Report

This course is for programmers who know Python well. It covers only what JavaScript’s loops do differently. Your project is a night-bus team’s morning report, a Python script you’ll port to JavaScript. Its first loop prints last night’s delays:

Language: Python
delays = [4, 0, 12]
for delay in delays:
    print(delay)

Here’s a JavaScript port that still says in, like Python, as plenty of code online does:

Language: JavaScript
const delays = [4, 0, 12];
for (const delay in delays) {
  console.log(delay);
}

It runs without an error and prints this:

Language: Program Output
0
1
2

Python prints 4, 0, and 12, but the JavaScript port prints 0, 1, and 2. Why? And what should you write instead? This course answers both: loops are where Python habits often fail silently.

The team’s script starts with that loop. Its report has four parts: the late departures, the delay totals per route, the first canceled trip, and the route supervisors. The team is moving its tools to JavaScript, so you’ll port the script one loop at a time.

By the end of this course, you’ll be able to:

  • Loop over items with for...of, and tell it apart from for...in
  • Count without range(), with the classic for loop
  • Loop until something happens, and search without for...else
  • Loop over positions, pairs, objects, and Maps without enumerate(), zip(), or .items()
  • Port the whole night-bus report to JavaScript

You should know Python’s loops, including enumerate(), zip(), and looping over a dictionary, and the JavaScript basics: const and let, functions and arrow functions, arrays and objects. You’ll also need a current version of Node.js and a project set up for ES modules (ECMAScript modules), with "type": "module" in its package.json. The examples use Node 26 and Python 3.15.

Short videos mix with text lessons and exercises, and every video has a summary below it. A quiz and a summary close the course.

Up next: Looping Over Items With for…of, which starts with this same loop.

Download

Sample Code (.zip)

10.1 KB
Download

Course Slides (.pdf)

610.4 KB

00:00 Welcome to JavaScript Loops for Pythonistas! This course is for programmers who know Python well, and it covers only what JavaScript’s loops do differently.

00:11 Your project is a night-bus team’s morning report, a Python script you’ll port to JavaScript. Here’s a first taste. This Python loop prints last night’s bus delays.

00:24 Here’s a JavaScript port that still says in, like Python, as plenty of code online does. It prints zero, one, two. No error, and those aren’t the delays. Why?

00:38 And what should you write instead? This course answers both: loops are where Python habits often fail silently.

00:48 The team’s script starts with this loop. Its report has four parts. The team is moving to JavaScript, so you’ll port it one loop at a time.

01:00 You’ll loop over items and count without range(). You’ll loop until something happens, search without for…else, and loop over pairs, objects, and Maps without enumerate(), zip(), or .items().

01:13 The project puts it all together.

01:16 You should know Python’s loops, with enumerate(), zip(), and dicts, and the JavaScript basics: const and let, functions and arrows, arrays and objects. You also need a current version of Node in a project set up for ES modules.

01:32 The examples use Node 26 and Python 3.15.

01:37 Short videos mix with text lessons and exercises, and every video has a summary below it. A quiz and a summary close the course. The next video, Looping Over Items With for…of, starts with this same loop.

Become a Member to join the conversation.