An amusement park charges $18 per person for entry. A group of friends is going together. There is also a $25 parking fee for the whole group. Write an expression for the total cost where p is number of people.
Functions allow us to calculate costs for any group size instantly.
function calculateTripCost(people) {
const entryPerPerson = 18; // $18/person
const parkingFee = 25; // Flat fee
// Expression: 18p + 25
return (entryPerPerson * people) + parkingFee;
}
// 4 friends going:
console.log(calculateTripCost(4));
// Calculation: (18 * 4) + 25 = 72 + 25 = 97
// Output: 97