Skip to content
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

Solution #5120

Open
wants to merge 1 commit 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
16 changes: 15 additions & 1 deletion src/calculateRentalCost.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,22 @@
*
* @return {number}
*/
const LONG_VACATION = 7;
const LONG_VACATION_DISCOUNT = 50;
const SHORT_VACATION = 3;
const SHORT_VACATION_DISCOUNT = 20;
const ONE_DAY_RENT = 40;

function calculateRentalCost(days) {
// write code here
if (days >= LONG_VACATION) {
return ONE_DAY_RENT * days - LONG_VACATION_DISCOUNT;

Choose a reason for hiding this comment

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

Consider using parentheses for clarity in the calculation: return (ONE_DAY_RENT * days) - LONG_VACATION_DISCOUNT;. This makes the order of operations explicit, although it is not strictly necessary due to operator precedence.

}

if (days >= SHORT_VACATION) {
return ONE_DAY_RENT * days - SHORT_VACATION_DISCOUNT;

Choose a reason for hiding this comment

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

Similar to the previous comment, consider using parentheses for clarity: return (ONE_DAY_RENT * days) - SHORT_VACATION_DISCOUNT;.

}
Comment on lines +13 to +19

Choose a reason for hiding this comment

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

The logic for applying discounts is correct, but ensure that the conditions are mutually exclusive. Since the LONG_VACATION condition is checked first, it correctly prevents the SHORT_VACATION discount from being applied when the LONG_VACATION condition is met.


return ONE_DAY_RENT * days;
}

module.exports = calculateRentalCost;
Loading