A taxi service charges a $3.00 base fee plus $2.00 per mile. Let m be the number of miles. Write an expression for the total cost.
This "mx + b" pattern appears everywhere in programming. From animation progress to subscription pricing.
function getTaxiCost(miles) {
const baseFee = 3.00; // Fixed (b)
const ratePerMile = 2.00; // Rate (m)
// y = mx + b
return (ratePerMile * miles) + baseFee;
}
// 10 mile ride: (2 * 10) + 3
console.log(getTaxiCost(10)); // Output: 23