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

Develop #4872

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Develop #4872

Changes from 3 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
17 changes: 16 additions & 1 deletion src/calculateRentalCost.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@
* @return {number}
*/
function calculateRentalCost(days) {
// write code here
const shortTerm = 3;

Choose a reason for hiding this comment

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

Suggested change
const shortTerm = 3;
const SHORT_TERM = 3;

Consider using the checklist https://github.com/mForkosh/js_task-transportation-on-vacation/blob/develop/checklist.md to complete the task

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;

Choose a reason for hiding this comment

The 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;
Loading