Skip to content

Commit

Permalink
moving constants over function and deleting else
Browse files Browse the repository at this point in the history
  • Loading branch information
k0tlik02 committed Oct 30, 2024
1 parent cccee52 commit 798a75d
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/calculateRentalCost.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
*
* @return {number}
*/
const RENTCOSTFORONEDAY = 40;
const LONG_TERM_DISCOUNT = 50;
const SHORT_TERM_DISCOUNT = 20;
const LONG_TERM = 7;
const SHORT_TERM = 3;

function calculateRentalCost(days) {
const rentCostForOneDay = 40;
const LONG_TERM_DISCOUNT = 50;
const SHORT_TERM_DISCOUNT = 20;
const LONG_TERM = 7;
const SHORT_TERM = 3;
let totalCost = rentCostForOneDay * days;
const totalCost = RENTCOSTFORONEDAY * days;

if (days >= LONG_TERM) {
totalCost -= LONG_TERM_DISCOUNT;
} else if (days >= SHORT_TERM) {
totalCost -= SHORT_TERM_DISCOUNT;
return totalCost - LONG_TERM_DISCOUNT;
}

if (days >= SHORT_TERM) {
return totalCost - SHORT_TERM_DISCOUNT;
}

return totalCost;
Expand Down

0 comments on commit 798a75d

Please sign in to comment.