-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
function returns the total amount for different number of days #4986
base: master
Are you sure you want to change the base?
Conversation
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.
It looks like there's a small issue with how discounts are applied in your calculateRentalCost
function. Currently, only one discount is applied even if both conditions for discounts are met. To ensure the correct discount is applied, you might want to adjust the logic to consider both discounts when the rental period is 7 days or more. Keep up the great work, and once you fix this, your solution will be spot on! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
src/calculateRentalCost.js
Outdated
if (DAYS >= LONG_TERM) { | ||
const LONG_TERM_TOTAL = DAYS * ONE_DAY_PRISE - LONG_TERM_DISCOUNT; | ||
|
||
return LONG_TERM_TOTAL; | ||
} | ||
|
||
if (DAYS >= MIDDLE_TERM) { | ||
const MIDDLE_TERM_TOTAL = DAYS * ONE_DAY_PRISE - MIDDLE_TERM_DISCOUNT; | ||
|
||
return MIDDLE_TERM_TOTAL; | ||
} |
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 logic for applying discounts is incorrect. If the number of days is greater than or equal to 7, both the 7-day and 3-day discounts should be considered. Currently, only the 7-day discount is applied. You should adjust the logic to ensure that the correct discount is applied based on the number of days. Consider using a single return statement at the end of the function to calculate the total cost after determining the applicable discount.
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.
Review Summary
Great effort on implementing the calculateRentalCost
function! 🎉 While the logic for applying discounts is on the right track, there are a few areas that need improvement to fully meet the task requirements:
-
Discount Logic: Ensure that the correct discount is applied based on the rental period. If the rental period is 7 days or more, a $50 discount should be applied. If it's 3 days or more but less than 7 days, a $20 discount should be applied.
-
Use of Constants: Avoid using hardcoded literals for discount values and the number of days. Define constants for these values to make your code more maintainable and readable.
-
Variable Declaration: Use
const
instead oflet
for thePRICE
variable since its value does not change after initialization. This aligns with best practices and the checklist requirements. -
Conditional Logic: Simplify your conditional logic by using
if
statements withreturn
instead ofelse if
. This will make your code cleaner and easier to follow.
By addressing these points, you'll improve the structure and readability of your code. Remember, these changes are crucial for maintaining code quality and ensuring that your solution meets the task requirements. Keep up the good work, and use this feedback to enhance your coding skills! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
if (days >= 7) { | ||
PRICE -= 50; | ||
} else if (days >= 3) { | ||
PRICE -= 20; |
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 current logic applies only one discount based on the rental period. According to the task requirements, if the rental period is 7 days or more, a $50 discount should be applied. If the rental period is 3 days or more but less than 7 days, a $20 discount should be applied. Ensure that the correct discount is applied based on these conditions.
No description provided.