From 40298cea8743e53fffefed4df52a09bae1317c96 Mon Sep 17 00:00:00 2001 From: Vlada Lavrentieva Date: Mon, 9 Dec 2024 22:29:55 +0100 Subject: [PATCH 1/2] function returns the total amount for different number of days --- src/calculateRentalCost.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/calculateRentalCost.js b/src/calculateRentalCost.js index 1e3a27d11..6224a2b43 100644 --- a/src/calculateRentalCost.js +++ b/src/calculateRentalCost.js @@ -4,7 +4,26 @@ * @return {number} */ function calculateRentalCost(days) { - // write code here + const DAYS = days; + const ONE_DAY_PRISE = 40; + const LONG_TERM = 7; + const LONG_TERM_DISCOUNT = 50; + const MIDDLE_TERM = 3; + const MIDDLE_TERM_DISCOUNT = 20; + + 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; + } + + return DAYS * ONE_DAY_PRISE; } module.exports = calculateRentalCost; From 7095d0eccfbd59f074d63ed26ff8b406ad06a4cc Mon Sep 17 00:00:00 2001 From: Vlada Lavrentieva Date: Mon, 9 Dec 2024 23:01:32 +0100 Subject: [PATCH 2/2] make short code --- src/calculateRentalCost.js | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/calculateRentalCost.js b/src/calculateRentalCost.js index 6224a2b43..f302907b8 100644 --- a/src/calculateRentalCost.js +++ b/src/calculateRentalCost.js @@ -4,26 +4,15 @@ * @return {number} */ function calculateRentalCost(days) { - const DAYS = days; - const ONE_DAY_PRISE = 40; - const LONG_TERM = 7; - const LONG_TERM_DISCOUNT = 50; - const MIDDLE_TERM = 3; - const MIDDLE_TERM_DISCOUNT = 20; + let PRICE = days * 40; - 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; + if (days >= 7) { + PRICE -= 50; + } else if (days >= 3) { + PRICE -= 20; } - return DAYS * ONE_DAY_PRISE; + return PRICE; } module.exports = calculateRentalCost;