From 9bca09f1bc1aab9b16a62fb4cf014c01b5370a91 Mon Sep 17 00:00:00 2001 From: Kateryna Shepel Date: Mon, 20 Jan 2025 20:07:51 +0200 Subject: [PATCH 1/2] Solution --- src/calculateRentalCost.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/calculateRentalCost.js b/src/calculateRentalCost.js index 1e3a27d11..a9b8cdc16 100644 --- a/src/calculateRentalCost.js +++ b/src/calculateRentalCost.js @@ -4,7 +4,24 @@ * @return {number} */ function calculateRentalCost(days) { - // write code here + const priceOfRent = 40; + let totalCost = days * priceOfRent; + const smallDiscount = 20; + const bigDiscount = 50; + + if (days < 3) { + return totalCost; + } + + if (days >= 3 && days <= 6) { + totalCost = totalCost - smallDiscount; + + return totalCost; + } + + totalCost = totalCost - bigDiscount; + + return totalCost; } module.exports = calculateRentalCost; From e076afa796953b3060a08b9c86a8fc9a2d79095e Mon Sep 17 00:00:00 2001 From: Kateryna Shepel Date: Tue, 21 Jan 2025 13:31:20 +0200 Subject: [PATCH 2/2] Solution --- src/calculateRentalCost.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/calculateRentalCost.js b/src/calculateRentalCost.js index a9b8cdc16..bed4aee6f 100644 --- a/src/calculateRentalCost.js +++ b/src/calculateRentalCost.js @@ -4,22 +4,24 @@ * @return {number} */ function calculateRentalCost(days) { - const priceOfRent = 40; - let totalCost = days * priceOfRent; - const smallDiscount = 20; - const bigDiscount = 50; + const PRICE_OF_RENT = 40; + let totalCost = days * PRICE_OF_RENT; + const SHORT_TERM = 3; + const SMALL_DISCOUNT = 20; + const LONG_TERM = 7; + const BIG_DISCOUNT = 50; - if (days < 3) { + if (days < SHORT_TERM) { return totalCost; } - if (days >= 3 && days <= 6) { - totalCost = totalCost - smallDiscount; + if (days < LONG_TERM) { + totalCost = totalCost - SMALL_DISCOUNT; return totalCost; } - totalCost = totalCost - bigDiscount; + totalCost = totalCost - BIG_DISCOUNT; return totalCost; }