Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/calculateRentalCost.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,23 @@
* @return {number}
*/
function calculateRentalCost(days) {
// write code here
const rentalPrice = 40;
const discountFor3OrMostday = 20;
const discountFor7OrMostday = 50;
const rentalDayForDiscount20 = 3;
const rentalDayForDiscount50 = 7;
Comment on lines +7 to +11

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's great that you've replaced magic numbers with named constants! To make this even more readable and align with the checklist's examples, consider naming constants based on the concept they represent, rather than their value.

Also, there's a small typo in ...OrMostday; it should likely be ...OrMoreDays.

Here's a suggestion for a more conventional naming scheme:

const COST_PER_DAY = 40;
const LONG_TERM_DISCOUNT = 50;
const MEDIUM_TERM_DISCOUNT = 20;
const LONG_TERM_DAYS_THRESHOLD = 7;
const MEDIUM_TERM_DAYS_THRESHOLD = 3;


const rentalSum = rentalPrice * days;

if (days >= rentalDayForDiscount50) {
return rentalSum - discountFor7OrMostday;
}

if (days >= rentalDayForDiscount20) {
return rentalSum - discountFor3OrMostday;
}

return rentalSum;
}

module.exports = calculateRentalCost;