From 21e7ba01df68273b5d44121051b34d8d4dc694d3 Mon Sep 17 00:00:00 2001 From: Che Date: Thu, 31 Oct 2024 16:58:56 +0000 Subject: [PATCH] Solution --- src/calculateRentalCost.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/calculateRentalCost.js b/src/calculateRentalCost.js index 1e3a27d11..e100994d3 100644 --- a/src/calculateRentalCost.js +++ b/src/calculateRentalCost.js @@ -4,7 +4,28 @@ * @return {number} */ function calculateRentalCost(days) { - // write code here + let totalPrice = 0; + const cost = 40; + const longTermDiscount = 50; + const shortTermDiscount = 20; + const longRental = 7; + const mediumRental = 3; + + if (days >= longRental) { + totalPrice += cost * days - longTermDiscount; + + return totalPrice; + } + + if (days >= mediumRental) { + totalPrice += cost * days - shortTermDiscount; + + return totalPrice; + } + + totalPrice += cost * days; + + return totalPrice; } module.exports = calculateRentalCost;