-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Solution #5114
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
base: master
Are you sure you want to change the base?
Solution #5114
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,16 @@ | |
* | ||
* @return {number} | ||
*/ | ||
|
||
function calculateRentalCost(days) { | ||
// write code here | ||
const COST_CAR_DAY = 40; | ||
const COST_CAR_DISCOUNT = days >= 7 ? 50 : 20; | ||
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 discount logic here applies a discount of 50 for 7 or more days and 20 for 3 to 6 days. According to the task requirements, the discount should only be applied if the rental period is 3 or more days, and the discount amount should be consistent. Please adjust the logic to ensure the discount is only applied when |
||
|
||
if (days >= 3) { | ||
return days * COST_CAR_DAY - COST_CAR_DISCOUNT; | ||
} | ||
|
||
return days * COST_CAR_DAY; | ||
} | ||
|
||
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.
The discount logic is incorrect. According to the requirements, a discount should only be applied if the rental period is 3 or more days. The current logic applies a discount for any number of days, which is not correct. Consider revising the condition to apply the discount only when
days >= 3
.