From 338b660734d87cae0330e69681edbbf8429acb2f Mon Sep 17 00:00:00 2001 From: Ilya Ilchuk Date: Mon, 28 Oct 2024 16:00:06 +0200 Subject: [PATCH] update solution --- src/calculateRentalCost.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/calculateRentalCost.js b/src/calculateRentalCost.js index bc48f3998..a59f2d0e2 100644 --- a/src/calculateRentalCost.js +++ b/src/calculateRentalCost.js @@ -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;