Skip to content

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

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
10 changes: 9 additions & 1 deletion src/calculateRentalCost.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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.

Choose a reason for hiding this comment

The 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 days >= 3 and use the correct discount value.


if (days >= 3) {
return days * COST_CAR_DAY - COST_CAR_DISCOUNT;
}

return days * COST_CAR_DAY;
}

module.exports = calculateRentalCost;
Loading