-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
base: master
Are you sure you want to change the base?
Solution #5120
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
|
||
if (days >= SHORT_VACATION) { | ||
return ONE_DAY_RENT * days - SHORT_VACATION_DISCOUNT; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the previous comment, consider using parentheses for clarity: |
||
} | ||
Comment on lines
+13
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
return ONE_DAY_RENT * days; | ||
} | ||
|
||
module.exports = calculateRentalCost; |
There was a problem hiding this comment.
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.