#Problem with Freelancer Rates Task 3.

26 messages · Page 1 of 1 (latest)

clear kiln
#

I have a difference of > 10000.
I need some advice; I’m a bit lost in the code at the moment.
Also, I don’t think my code style is perfect and it needs some corrections.
(')
/**

  • Calculates the discounted rate for large projects, rounded up
  • @param {number} ratePerHour
  • @param {number} numDays: number of days the project spans
  • @param {number} discount: for example 20% written as 0.2
  • @returns {number} the rounded up discounted rate
    */
    export function priceWithMonthlyDiscount(ratePerHour, numDays, discount) {

const percentigCost = 1 - discount;
const rateByDay = ratePerHour8;
const wholeMonthCount = Math.floor(numDays / 22);
const costsMonth = rateByDay
22* percentigCost;
const remainingMonth = numDays % 22;
const remainigDays = Math.ceil(remainingMonth * 22);
const costs = (costsMonth * wholeMonthCount) + (remainigDays * rateByDay);
return Math.ceil(costs);
}
(')
failure report________
Code Run

expect(received).toBeCloseTo(expected, precision)

Test Failure

Expected: 8960
Received: 19712

Expected precision: 6
Expected difference: < 0.0000005
Received difference: 10752

sterile bear
#

numDays % 22 -- what are the units of the result. Is it months?

clear kiln
#

It should be the remaining days, roughly 10 days rounded up.

echo questBOT
#

Increase your chance of getting help and look like a pro by sharing codeblocks not images. For example, you can type the following. Note, the ``` must be on their own line.
```
for number in range(10):
total += number;
```
Discord will render that as so:

for number in range(10):
    total += number;

Click here to learn more about codeblocks, including how to indicate the programming language: https://exercism.org/docs/community/being-a-good-community-member/writing-support-requests and http://bit.ly/howto-ask

knotty girder
#

It should be the remaining days, roughly 10 days rounded up.
Then why is its result stored in a variable named remainingMonth?
And how does that variable contribute to the result of the function?

clear kiln
#

I thought I had about 230 days, which equals approximately 10.4545 months.
For 10 months, the discount applies, and the remaining 0.4545 months, multiplied by 22 days per month, equals roughly 10 days without a discount.

knotty girder
#

Let's assume that's correct. So how does the variable remainingMonth (which stores a number of days!) contribute to the result of the function.

clear kiln
#

remainingMonth is rounded up and multiplied by 22, resulting in the 10 days. Stored in remainigDays.

knotty girder
#

remainingMonth is rounded up and multiplied by 22, resulting in 10 days.
Really? Let's go with concrete values and remainingMonth holds the value 10, the number of days.
Then it gets multiplied with 22. So you have the value 220.
This gets rounded up (but it's already an integer so it remains 220.)
This value 220 gets stored in remainigDays.

clear kiln
#

I thought it was only 0.4545. I’m working in the Exercism environment and I don’t know how to debug there. Maybe that’s the problem.

knotty girder
#

That's why glenn_j was asking about numDays % 22. It's not a fraction (like 0.45) but the remainder of the division (like 10).

clear kiln
#

After removing the 22, it is correct.
I’m now looking for a compiler with debugging features so I can see my problems directly.

knotty girder
#

You can write to the console:

  console.log(`remainingMonth=${remainingMonth} remainigDays=${remainigDays}`);
#

If a test fails the output will be shown like this:

Your Output

"remainingMonth=4 remainigDays=88"
echo questBOT
#

If everything is resolved, we ask that the person who posted the request react to the top/original post with a :white_check_mark: (:white_check_mark:). This indicates to others that this issue has been resolved and locks the thread.
If all the tests pass and you want to further improve your solution, we encourage you to use the "Request a Code Review" feature on the website!

arctic lance
clear kiln
arctic lance
#

30/22 is 1 with a remainder of 8

#

30%22 gives the remainer of 8

#

Does that make sense, @clear kiln ?

clear kiln
arctic lance
#

Exactly!

echo questBOT
#

If everything is resolved, we ask that the person who posted the request react to the top/original post with a :white_check_mark: (:white_check_mark:). This indicates to others that this issue has been resolved and locks the thread.
If all the tests pass and you want to further improve your solution, we encourage you to use the "Request a Code Review" feature on the website!

arctic lance
#

@clear kiln Is this all working now? Did you have any other questions?

clear kiln
#

it is running now

#

maybe at the following exercises.