export function priceWithMonthlyDiscount(ratePerHour, numDays, discount) {
let hoursPerDay = 8;
let billableDays = 22;
let hourlyRate = ratePerHour * (1 - discount);
let Month = Math.floor(numDays / billableDays);
let monthlyCost =Month * billableDays * hoursPerDay * hourlyRate;
let remainingDays = numDays % billableDays;
let remainingDaysCost =remainingDays * hoursPerDay * hourlyRate;
let totalCost = Math.round(monthlyCost + remainingDaysCost)
return totalCost;
}
priceWithMonthlyDiscount()
#Its failing two tests i don't why is it failing
19 messages · Page 1 of 1 (latest)
What was the test? What was the error? How did it fail basically
let me show u
CODE RUN
const actual = priceWithMonthlyDiscount(16, 130, 0.15);
const expected = 14528;
expect(actual).toBeCloseTo(expected, DIFFERENCE_PRECISION_IN_DIGITS);
TEST FAILURE
Error: expect(received).toBeCloseTo(expected, precision)
Expected: 14528
Received: 14144
Expected precision: 6
Expected difference: < 0.0000005
Received difference: 384```
i think i made a mistake in calculations
Are you applying the discount to full months only?
And the remaining days are charged at the full (not discounted) rate?
okay so the hourly rate is dicounted
than am multiplying it with remaining days cost and monthly cost
check the code there i first discounted the ratePerHour
so that means i shouldn't apply discount to remaining days
they should be charged fully
Correct
ok let me try that