A freelancer is hired for a project. The base payment is $500. For every additional hour (h) worked beyond the agreed 20 hours, they earn $35 per extra hour. They also spend $50 on software tools. Write an expression for the total profit after paying for the tools.
Business logic often simply translates these math expressions into functions.
function calculateProfit(extraHours: number): number {
const basePay = 500;
const hourlyRate = 35;
const expenses = 50;
// Expression: 500 + 35h - 50
// Income (Base + Variable) - Expenses
return basePay + (hourlyRate * extraHours) - expenses;
}
// 10 extra hours:
console.log(calculateProfit(10));
// 500 + (35 * 10) - 50
// 500 + 350 - 50 = 800