Loading video player…

Welcome to the Roastery Batch Planner

This course is about JavaScript’s numbers next to Python’s: dividing, rounding, reading them from text, and formatting them. JavaScript arithmetic rarely stops with an error, so a port that looks right can print the wrong number. Along the way, you’ll port a coffee roastery’s Python batch planner.

The roastery roasts raw, green coffee beans in a drum. Each evening, its planner turns tomorrow’s order into green beans, batches, bags, and cost. Here’s a first taste. The planner counts the full 12 kg batches the drum takes. These are its batch lines in Python:

Language: Python
WEIGHT_LOSS = 0.15
DRUM_KG = 12

order_kg = 37.5
green_kg = order_kg / (1 - WEIGHT_LOSS)
full_batches = int(green_kg // DRUM_KG)
print(f"Batches: {full_batches} full")

Python prints three full batches:

Language: Program Output
Batches: 3 full

Here are the same lines ported line by line to JavaScript. The batches line keeps its //:

Language: JavaScript
const WEIGHT_LOSS = 0.15;
const DRUM_KG = 12;

const orderKg = 37.5;
const greenKg = orderKg / (1 - WEIGHT_LOSS);
const fullBatches = greenKg // DRUM_KG;
console.log(`Batches: ${fullBatches} full`);

Run it, and the batch count comes out as 44 with 14 decimals:

Language: Program Output
Batches: 44.11764705882353 full

There’s no error and no warning.

The roastery is two people, selling mostly to cafés, and the roaster pastes in each big order. The order dashboard runs on JavaScript, so you’ll port the planner, one kind of line at a time.

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

  • Work with one number type, and divide with Math.floor() and %
  • Round with Math.round() and Math.ceil(), without the math module
  • Read numbers from text with Number(), parseInt() and parseFloat()
  • Format numbers for people with .toFixed() and Intl.NumberFormat
  • Port the whole batch planner to JavaScript

You need to know Python’s arithmetic with int and float (//, %, ** and the math module), rounding with round(), and format specs such as :.2f. In JavaScript, you need to know how to write small programs with const, let, if, functions and template literals, and know its types and ===. Any current version of Node.js is fine: the examples use Node 26 and Python 3.15.

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

Next is a text lesson, Working With One Number Type, which puts Python’s int and float next to JavaScript’s single number type.

Download

Sample Code (.zip)

8.9 KB
Download

Course Slides (.pdf)

990.7 KB

00:02 Welcome to JavaScript Numbers for Pythonistas! It’s about JavaScript’s numbers next to Python’s: dividing, rounding, reading, and formatting them. JavaScript arithmetic rarely stops with an error, so a port that looks right can print the wrong number.

00:19 You’ll port a coffee roastery’s Python batch planner. Here’s a first taste. The roastery roasts raw, green coffee beans in a drum. Each evening, its planner turns tomorrow’s order into green beans, batches, bags, and cost.

00:37 The planner counts the full twelve kilo batches the drum takes, and Python prints three. In a line-by-line port, this line keeps its //, as in Python.

00:50 Run it, and the batch count comes out as forty-four, with fourteen decimals. There’s no error and no warning.

01:00 The roastery is two people, selling mostly to cafés. The roaster pastes in each big order, and the planner works out the numbers. The order dashboard runs on JavaScript, so you’ll port the planner, one kind of line at a time.

01:16 You’ll work with one number type, divide, round with Math, and read numbers from pasted text. You’ll format numbers for people. And the project ports the whole planner.

01:30 You need to know Python’s arithmetic, rounding, and format specs, and how to write small JavaScript programs. Any current Node is fine.

01:41 Videos mix with text lessons and exercises, and every video has a summary below it. A quiz and a summary close the course. Next is a text lesson, Working With One Number Type, which puts Python’s int and float next to JavaScript’s single number type.

Become a Member to join the conversation.