Skip to content

Commit

Permalink
move constants outside the function and created new const
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeoneishin committed Oct 29, 2024
1 parent 2b456ce commit d728230
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/calculateRentalCost.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
*
* @return {number}
*/
const PRICE_FOR_DAY = 40;
const LONG_TERM = 7;
const LONG_TERM_DISCOUNT = 50;
const SHORT_TERM = 3;
const SHORT_TERM_DISCOUNT = 20;

function calculateRentalCost(days) {
const PRICE_FOR_DAY = 40;
const LONG_TERM = 7;
const LONG_TERM_DISCOUNT = 50;
const SHORT_TERM = 3;
const SHORT_TERM_DISCOUNT = 20;
const currentPrice = days * PRICE_FOR_DAY;

if (days >= LONG_TERM) {
return days * PRICE_FOR_DAY - LONG_TERM_DISCOUNT;
return currentPrice - LONG_TERM_DISCOUNT;
}

if (days >= SHORT_TERM) {
return days * PRICE_FOR_DAY - SHORT_TERM_DISCOUNT;
return currentPrice - SHORT_TERM_DISCOUNT;
}

return days * PRICE_FOR_DAY;
return currentPrice;
}

module.exports = calculateRentalCost;

0 comments on commit d728230

Please sign in to comment.