Skip to content

Solution #5122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
21 changes: 20 additions & 1 deletion src/calculateRentalCost.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,26 @@
* @return {number}
*/
function calculateRentalCost(days) {
// write code here
const PRICE_OF_RENT = 40;
let totalCost = days * PRICE_OF_RENT;
const SHORT_TERM = 3;
const SMALL_DISCOUNT = 20;
const LONG_TERM = 7;
const BIG_DISCOUNT = 50;
Comment on lines +7 to +12

Choose a reason for hiding this comment

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

Please declare consts outside functions if possible - with your solution you re-declare these variables on each function call


if (days < SHORT_TERM) {
return totalCost;
}

if (days < LONG_TERM) {
totalCost = totalCost - SMALL_DISCOUNT;

return totalCost;
}

totalCost = totalCost - BIG_DISCOUNT;

return totalCost;
Comment on lines +18 to +26

Choose a reason for hiding this comment

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

No need to reassign totalCost
Just return what you need

Suggested change
if (days < LONG_TERM) {
totalCost = totalCost - SMALL_DISCOUNT;
return totalCost;
}
totalCost = totalCost - BIG_DISCOUNT;
return totalCost;
if (days < LONG_TERM) {
return totalCost - SMALL_DISCOUNT;
}
return totalCost - BIG_DISCOUNT;

If you do this - you can change
let totalCost = days * PRICE_OF_RENT; to
const totalCost = days * PRICE_OF_RENT;

}

module.exports = calculateRentalCost;
Loading