m4n50
January 6, 2023, 4:30pm
1
Something I can’t see. I’m doing wrong.
export function dayRate(ratePerHour) {
return ratePerHour * 8;
}
export function priceWithMonthlyDiscount(ratePerHour, numDays, discount) {
const fullMonthBill = dayRate(ratePerHour) * 22;
const monthsWithDiscount = Math.floor(numDays / 22) * fullMonthBill * discount;
const remainingDays = numDays % 22;
const remainingCost = remainingDays * dayRate(ratePerHour);
const totalPrice = monthsWithDiscount + remainingCost;
return Math.ceil(totalPrice);
}
Any thoughts?
glennj
January 6, 2023, 5:28pm
2
The difficulty is how you’re applying the discount.
the monthsWithDiscount should not be the months bill times the discount, it should be times 100% minus the discount
To reduce the bill by 10%, you want to multiply by 90%
From a code review perspective, store the “magic numbers” as constants with sensible names.
return ratePerHour * HOURS_PER_DAY;
...
fullMonthBill = dayRate(ratePerHour) * WORKING_DAYS_PER_MONTH;
@m4n50 , May I suggest that you update the title of the post to include the name of the exercise (freelancer-rates), if it is possible - this would help others who get stuck on the similar problem might be able to see the guidance offered by @glennj and benefit from that?