diff --git a/index.js b/index.js index 0db6949168..166dae1e51 100644 --- a/index.js +++ b/index.js @@ -1 +1,33 @@ -// Code your solution in this file! +function distanceFromHqInBlocks (blockNumber) { + if (blockNumber > 42) { + return blockNumber - 42; + } else { + return 42 - blockNumber; + } +} + +function distanceFromHqInFeet (blockNumber) { + return distanceFromHqInBlocks(blockNumber) * 264; +} + +function distanceTravelledInFeet (start, destination) { + if (start > destination) { + return (start - destination) * 264; + } else { + return (destination - start) * 264; + } + } + + function calculatesFarePrice (start, destination) { + const distance = distanceTravelledInFeet(start, destination); + + if (distance <= 400) { + return 0 ; + } else if (distance <= 2000) { + return (distance - 400) * .02; + } else if (distance <= 2500) { + return 25; + } else { + return 'cannot travel that far'; + } + }