#Its failing two tests i don't why is it failing

19 messages · Page 1 of 1 (latest)

gloomy dome
#
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()
#

i tried using Math.ceil and Math.floor it's not passing the tests

primal pendant
#

What was the test? What was the error? How did it fail basically

gloomy dome
#

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

deep creek
#

Are you applying the discount to full months only?

gloomy dome
#

yup

#

am applying dicount to everyhour

deep creek
#

And the remaining days are charged at the full (not discounted) rate?

gloomy dome
#

than am multiplying it with remaining days cost and monthly cost

deep creek
#

Full months get a discounted rate

#

The remaining days are charged at the full rate.

gloomy dome
#

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

deep creek
#

Correct

gloomy dome
#

ok let me try that