From d9f1d629b28bcbac550c82135d995a0cd1a27e2e Mon Sep 17 00:00:00 2001 From: Nihar Patel Date: Tue, 6 May 2025 11:25:07 -0400 Subject: [PATCH 1/3] Declare distanceFromHQInBlocks function --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 0db6949168..3aa4746083 100644 --- a/index.js +++ b/index.js @@ -1 +1,3 @@ -// Code your solution in this file! +function distanceFromHqInBlocks(street) { + return Math.abs(42 - street); +} From 9c6dfbb88bebc3c5972342208248bca60996e616 Mon Sep 17 00:00:00 2001 From: Nihar Patel Date: Tue, 6 May 2025 13:13:01 -0400 Subject: [PATCH 2/3] declare distanceFromHqInFeet function --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index 3aa4746083..c8b2446453 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,7 @@ function distanceFromHqInBlocks(street) { return Math.abs(42 - street); } + +function distanceFromHqInFeet(feetToHQ) { + return distanceFromHqInBlocks(feetToHQ) * 264; +} \ No newline at end of file From d3ba463c397c71ab51f0535f0a787ae8b1e85ce9 Mon Sep 17 00:00:00 2001 From: Nihar Patel Date: Tue, 6 May 2025 14:07:55 -0400 Subject: [PATCH 3/3] clean the code --- index.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/index.js b/index.js index c8b2446453..4c886919d4 100644 --- a/index.js +++ b/index.js @@ -4,4 +4,22 @@ function distanceFromHqInBlocks(street) { function distanceFromHqInFeet(feetToHQ) { return distanceFromHqInBlocks(feetToHQ) * 264; +} + +function distanceTravelledInFeet(startingBlock, endingBlock) { + return Math.abs(startingBlock - endingBlock) * 264; +} + +function calculatesFarePrice(start, destination){ + const distance = Math.abs(start-destination)*264; + + if (distance <= 400){ + return 0; + } else if (distance > 400 && distance <= 2000){ + return (distance - 400)* .02; + } else if (distance > 2000 && distance <=2500){ + return 25; + } else { + return 'cannot travel that far'; + } } \ No newline at end of file