From 3e7a30543d81655247e54bfaa635feda3fce5aea Mon Sep 17 00:00:00 2001 From: Liam Simmons Date: Mon, 6 May 2024 13:58:39 -0400 Subject: [PATCH] Add pricing calculator --- index.js | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 0db6949168..959a03b2c5 100644 --- a/index.js +++ b/index.js @@ -1 +1,32 @@ -// Code your solution in this file! +function distanceFromHqInBlocks(someValue) { + return Math.abs(someValue - 42) + } + +function distanceFromHqInFeet(someValue) { + return distanceFromHqInBlocks(someValue) * 264; + } + + function distanceTravelledInFeet(start, destination) { + return Math.abs(start - destination) * 264 + } + + + function calculatesFarePrice(start, destination) { + if (distanceTravelledInFeet(start, destination) < 400){ + return 0 + } + else if (distanceTravelledInFeet(start, destination) < 2000){ + return [distanceTravelledInFeet(start, destination)-400] * .02 + } + else if (distanceTravelledInFeet(start, destination) < 2500){ + return 25 + } + else{ + return "cannot travel that far" + } + } + + + + +