Skip to content

Commit

Permalink
update solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya-Ilchuk committed Oct 28, 2024
1 parent 43022a2 commit 338b660
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/calculateRentalCost.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
*/
function calculateRentalCost(days) {
const PRICE = 40;

const LONG_TERM = 7;
const LONG_TERM_DISCOUNT = 50;

const SHORT_TERM = 3;
const SHORT_TERM_DISCOUNT = 20;
let bestPrice = 0;

if (days < 3) {
bestPrice = PRICE * days;
}
const bestPrice = days * PRICE;

if (days >= 3) {
bestPrice = PRICE * days - SHORT_TERM_DISCOUNT;
if (days >= LONG_TERM) {
return bestPrice - LONG_TERM_DISCOUNT;
}

if (days >= 7) {
bestPrice = PRICE * days - LONG_TERM_DISCOUNT;
if (days >= SHORT_TERM) {
return bestPrice - SHORT_TERM_DISCOUNT;
}

return bestPrice;
Expand Down

0 comments on commit 338b660

Please sign in to comment.