I don’t know how to solve the task below. Can someone help me?
Often, the freelancer’s clients hire them for projects spanning over multiple months. In these cases, the freelancer decides to offer a discount for every full month, and the remaining days are billed at day rate. Every month has 22 billable days. Help them estimate their cost for such projects, given an hourly rate, the number of days the project spans, and a monthly discount rate. The discount is always passed as a number, where
0.42. The result must be rounded up to the nearest whole number.
What language are you working in? Or do you want to discuss it abstractly?
@junedev Thanks. I know elixir has that exercise too, but I didn’t look up the actual instructions.
@Norb1 in this task, you are given an hourly rate, a number of days and the discount rate. Only the days in full months are discounted. You need to calculate how many of the days are part of full months, and how many days are leftover. The leftover days are not discounted. You can reuse the
yes it is a part of JS.
Hi are you still stuck? If yes, can you please post what you have tried so that i can figure out the best way to help you?
Can you help me? I am doing the same exercise and I’ve been stuck for over a week. I don’t know where my logic is failing but the code is not even passing the tests. Please see below, highly appreciated if you can share some light :)
export const priceWithMonthlyDiscount = function (
// Calculate Price Per Day based on the given price per hour.
const pricePerDay = dayRate(pricePerHour);
// Calculate discount to be applied
const daysInMonth = numDays - (numDays % 22); // every month has 22 billable days
const discount = pricePerDay * daysInMonth * discountPercentage;
// Calculate price for days in a month (price - discount)
const pricePerMonth = daysInMonth * pricePerDay - discount;
// Calculate price for remaining days
const priceExceedingDays = numDays % 22 * pricePerDay;
// Sum Up price for discounted Month + exceeding days
return priceExceedingDays + pricePerMonth;
The above code is the closest I have managed to get, it passes two tests but fails the last two:
Thanks for your help in advance!
All you are missing is just rounding the result.
Please change the last line to this and the 2 failing tests will pass.
return Math.ceil(priceExceedingDays + pricePerMonth);
Sorry to hear that you struggled with this for a week. But the good news is that we learn a lot more deeply when we allow ourselves to struggle and not lookup the answers immediately. Please let me know if you need further help.
Your code is very readable - excellent variable names, clear comments - there is so much to appreciate about your code :)
Don’t worry and embrace these moments - anyone who starts on anything new in programming faces similar moments. You are not alone! These are the moments that stick in our head and helps us to remember these ideas for a very long time (in this world of fleeting memory)