Congratulations, you made it to the end of the course! The roastery’s batch planner now runs in JavaScript. For tonight’s paste of "37.5", batch-plan.js prints the same four lines as batch_plan.py, with the same beans and the same bill.
In the last exercise, you ran it on the three orders the head roaster compares: "37.5", "", and "1_200". You made the JavaScript stop on the blank paste as Python’s float() does and plan the 1,200 kg order, so both scripts agree on all three.
In this course, you learned how to:
- Use
Numberfor the planner’s ordinary whole and decimal values, and askNumber.isInteger()whether the stored value is whole - Guard a division that Python would have stopped, because dividing by zero gives
NaN,Infinity, or-Infinitywith no error - Use
Math.floor(a / b)for the planner’s//calculation andMath.trunc()forint()on finite numbers, and where values can go below zero, pairMath.floor()with((a % n) + n) % nandMath.trunc()with% - Round with
Math, usingMath.ceil()for the bags andMath.round(x * 100) / 100for the cost to the cent - Convert a paste with
Number(), after treating blank text as missing, and check it withNumber.isNaN() - Read a number off the front of text such as
"17.5kg"withparseFloat() - Format numbers last with
.toFixed()andIntl.NumberFormat, with an explicit locale, for separators, euros, and percentages