-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Develop #4872
base: master
Are you sure you want to change the base?
Develop #4872
Changes from 3 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 |
---|---|---|
|
@@ -4,7 +4,22 @@ | |
* @return {number} | ||
*/ | ||
function calculateRentalCost(days) { | ||
// write code here | ||
const shortTerm = 3; | ||
const longTerm = 7; | ||
|
||
const shortTermDiscount = 20; | ||
const longTermDiscount = 50; | ||
|
||
const rentalPerDay = 40; | ||
const rentalPrice = rentalPerDay * days; | ||
|
||
if (days >= longTerm) { | ||
return rentalPrice - longTermDiscount; | ||
} else if (days >= shortTerm) { | ||
return rentalPrice - shortTermDiscount; | ||
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 current logic applies a long-term discount for rentals of 7 days or more and a short-term discount for rentals of 3 to 6 days. However, the discount is applied only once, and the function returns immediately after applying the first applicable discount. This logic is correct if only one discount is meant to be applied. If the intention is to apply both discounts cumulatively for rentals longer than 7 days, the logic needs to be adjusted. |
||
} | ||
|
||
return rentalPrice; | ||
} | ||
|
||
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 the checklist https://github.com/mForkosh/js_task-transportation-on-vacation/blob/develop/checklist.md to complete the task