With Math.floor() in place of //, the port of batch_plan.py now says the drum takes three full batches. The head roaster also needs the size of the last part batch.
Python gets that number from %, and JavaScript’s % gives the same answer for the planner’s weights. With a positive divisor, they part ways once the left side goes negative.
Weigh Out the Last Part Batch
Here are the Python script’s batch lines, without formatting:
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)
last_batch_kg = green_kg % DRUM_KG
print(f"Batches: {full_batches} full + {last_batch_kg} kg")
The port keeps the % line, with camelCase names and the previous lesson’s Math.floor() in place of //:
Language: JavaScript
const WEIGHT_LOSS = 0.15;
const DRUM_KG = 12;
const orderKg = 37.5;
const greenKg = orderKg / (1 - WEIGHT_LOSS);
const fullBatches = Math.floor(greenKg / DRUM_KG);
const lastBatchKg = greenKg % DRUM_KG;
console.log(`Batches: ${fullBatches} full + ${lastBatchKg} kg`);
Both scripts print the same line, decimals and all: