From 835fee7f1e1e45646c7648e03e8af4b58f0c8672 Mon Sep 17 00:00:00 2001 From: Emily Kanarek Date: Mon, 5 May 2025 15:07:53 -0400 Subject: [PATCH 1/3] Complete functions calculating distance in blocks and feet --- index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 0db6949168..84551d68f5 100644 --- a/index.js +++ b/index.js @@ -1 +1,11 @@ -// Code your solution in this file! +function distanceFromHqInBlocks(street) { + if (street >= 42) { + return street - 42; + } else { + return 42 - street; + } +} + +function distanceFromHqInFeet(street) { + return distanceFromHqInBlocks(street) * 264; +} \ No newline at end of file From 94819e435efd096923ecb5ce56c9f9607fbf8b98 Mon Sep 17 00:00:00 2001 From: Emily Kanarek Date: Mon, 5 May 2025 15:10:00 -0400 Subject: [PATCH 2/3] Complete distanceTravelledInFeet function --- index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/index.js b/index.js index 84551d68f5..fc9c7cbc9b 100644 --- a/index.js +++ b/index.js @@ -8,4 +8,12 @@ function distanceFromHqInBlocks(street) { function distanceFromHqInFeet(street) { return distanceFromHqInBlocks(street) * 264; +} + +function distanceTravelledInFeet(start, destination) { + if (start >= destination) { + return (start - destination) * 264; + } else { + return (destination - start) * 264; + } } \ No newline at end of file From 7cd8089765260099c7469fd019f59fed879ddcb4 Mon Sep 17 00:00:00 2001 From: Emily Kanarek Date: Mon, 5 May 2025 15:31:28 -0400 Subject: [PATCH 3/3] Complete calculatesFarePrice function --- index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/index.js b/index.js index fc9c7cbc9b..69565a7c9c 100644 --- a/index.js +++ b/index.js @@ -16,4 +16,17 @@ function distanceTravelledInFeet(start, destination) { } else { return (destination - start) * 264; } +} + +function calculatesFarePrice(start, destination) { + const distance = distanceTravelledInFeet(start, destination); + if (distance <= 400) { + return 0; + } else if (distance > 400 && distance <= 2000) { + return (distance - 400) * 0.02; + } else if (distance > 2000 && distance < 2500) { + return 25; + } else { + return 'cannot travel that far'; + } } \ No newline at end of file