From de8d7cd601e1d8a42f0d5f3769fc6c767b31bb2e Mon Sep 17 00:00:00 2001 From: AsyaDev <142207257+AsyaDev14@users.noreply.github.com> Date: Sat, 26 Oct 2024 17:45:18 +0300 Subject: [PATCH 1/2] Solution --- src/calculateRentalCost.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/calculateRentalCost.js b/src/calculateRentalCost.js index 1e3a27d11..d0e4e51a7 100644 --- a/src/calculateRentalCost.js +++ b/src/calculateRentalCost.js @@ -4,7 +4,18 @@ * @return {number} */ function calculateRentalCost(days) { - // write code here + const PRICE_PER_DAY = 40; + const LONG_TERM = 7; + const LONG_TERM_DISCOUNT = 50; + const SHORT_TERM = 3; + const SHORT_TERM_DISCOUNT = 20; + let basePrice = days * PRICE_PER_DAY; + if (days >= LONG_TERM) { + return basePrice - LONG_TERM_DISCOUNT; + } else if (days >= SHORT_TERM) { + return basePrice - SHORT_TERM_DISCOUNT; + } + return basePrice; } module.exports = calculateRentalCost; From 1204366ab27b2595617f5c2b80c7dfee0f369d0d Mon Sep 17 00:00:00 2001 From: AsyaDev <142207257+AsyaDev14@users.noreply.github.com> Date: Tue, 29 Oct 2024 14:41:24 +0200 Subject: [PATCH 2/2] fixed let to const & delete else block --- src/calculateRentalCost.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/calculateRentalCost.js b/src/calculateRentalCost.js index d0e4e51a7..4ef45426c 100644 --- a/src/calculateRentalCost.js +++ b/src/calculateRentalCost.js @@ -9,12 +9,15 @@ function calculateRentalCost(days) { const LONG_TERM_DISCOUNT = 50; const SHORT_TERM = 3; const SHORT_TERM_DISCOUNT = 20; - let basePrice = days * PRICE_PER_DAY; + const basePrice = days * PRICE_PER_DAY; + if (days >= LONG_TERM) { return basePrice - LONG_TERM_DISCOUNT; - } else if (days >= SHORT_TERM) { + } + if (days >= SHORT_TERM) { return basePrice - SHORT_TERM_DISCOUNT; } + return basePrice; }