From 0096ae896526f7d97754df2494ed5f0d9eb9ef7f Mon Sep 17 00:00:00 2001 From: Gabriella Massaro Date: Mon, 6 May 2024 17:50:14 -0400 Subject: [PATCH 1/2] Complete lab --- index.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/index.js b/index.js index 0db6949168..d6e1ad360d 100644 --- a/index.js +++ b/index.js @@ -1 +1,30 @@ // Code your solution in this file! + + +function distanceFromHqInBlocks(street){ + const hqBlock = 42; + return Math.abs(street - hqBlock); +} + + +function distanceFromHqInFeet(street) { + return distanceFromHqInBlocks(street) * 264; + } + + function distanceTravelledInFeet(start, destination) { + return Math.abs(distanceFromHqInFeet(start) - distanceFromHqInFeet(destination)); + } + + function calculatesFarePrice(start, destination) { + const distanceInFeet = distanceTravelledInFeet(start, destination); + + if (distanceInFeet <= 400) { + return 0; + } else if (distanceInFeet > 400 && distanceInFeet < 2000) { + return ((distanceInFeet - 400) * 0.02); + } else if ((distanceInFeet - 400) <= 2000) { + return 25; + } else if (distanceInFeet > 2500) { + return "cannot travel that far"; + } + } From 5e47968a4434647944a475da6d52fd5962484cee Mon Sep 17 00:00:00 2001 From: Gabriella Massaro Date: Mon, 6 May 2024 20:07:30 -0400 Subject: [PATCH 2/2] Fix formatting and remove unnecessary hq specification for distanceTravelledInFeet function --- index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index d6e1ad360d..43fc89ea3a 100644 --- a/index.js +++ b/index.js @@ -9,13 +9,13 @@ function distanceFromHqInBlocks(street){ function distanceFromHqInFeet(street) { return distanceFromHqInBlocks(street) * 264; - } +} - function distanceTravelledInFeet(start, destination) { - return Math.abs(distanceFromHqInFeet(start) - distanceFromHqInFeet(destination)); - } +function distanceTravelledInFeet(start, destination) { + return Math.abs(start - destination) * 264; +} - function calculatesFarePrice(start, destination) { +function calculatesFarePrice(start, destination) { const distanceInFeet = distanceTravelledInFeet(start, destination); if (distanceInFeet <= 400) { @@ -27,4 +27,4 @@ function distanceFromHqInFeet(street) { } else if (distanceInFeet > 2500) { return "cannot travel that far"; } - } +}