diff --git a/.results.json b/.results.json new file mode 100644 index 0000000000..1ae64ed041 --- /dev/null +++ b/.results.json @@ -0,0 +1,200 @@ +{ + "stats": { + "suites": 5, + "tests": 13, + "passes": 13, + "pending": 0, + "failures": 0, + "start": "2025-05-07T19:00:16.463Z", + "end": "2025-05-07T19:00:16.578Z", + "duration": 115 + }, + "tests": [ + { + "title": "returns a distance in blocks", + "fullTitle": "index.js distanceFromHqInBlocks() returns a distance in blocks", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "returns a distance in blocks", + "fullTitle": "index.js distanceFromHqInBlocks() returns a distance in blocks", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "calculates distances below 42nd street", + "fullTitle": "index.js distanceFromHqInBlocks() calculates distances below 42nd street", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "returns a distance in feet", + "fullTitle": "index.js distanceFromHqInFeet() returns a distance in feet", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "returns a distance in feet", + "fullTitle": "index.js distanceFromHqInFeet() returns a distance in feet", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "calculates distances below 42nd street", + "fullTitle": "index.js distanceFromHqInFeet() calculates distances below 42nd street", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "returns the distance travelled in feet", + "fullTitle": "index.js distanceTravelledInFeet() returns the distance travelled in feet", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "returns a distance in feet", + "fullTitle": "index.js distanceTravelledInFeet() returns a distance in feet", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "returns distance when destination is below distance", + "fullTitle": "index.js distanceTravelledInFeet() returns distance when destination is below distance", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "gives customers a free sample", + "fullTitle": "index.js calculatesFarePrice(start, destination) gives customers a free sample", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "charges 2 cents per foot when total feet travelled is between 400 and 2000 (remember the first 400 feet are free!)", + "fullTitle": "index.js calculatesFarePrice(start, destination) charges 2 cents per foot when total feet travelled is between 400 and 2000 (remember the first 400 feet are free!)", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "charges 25 dollars for a distance over 2000 feet", + "fullTitle": "index.js calculatesFarePrice(start, destination) charges 25 dollars for a distance over 2000 feet", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "does not allow rides over 2500 feet", + "fullTitle": "index.js calculatesFarePrice(start, destination) does not allow rides over 2500 feet", + "duration": 0, + "currentRetry": 0, + "err": {} + } + ], + "pending": [], + "failures": [], + "passes": [ + { + "title": "returns a distance in blocks", + "fullTitle": "index.js distanceFromHqInBlocks() returns a distance in blocks", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "returns a distance in blocks", + "fullTitle": "index.js distanceFromHqInBlocks() returns a distance in blocks", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "calculates distances below 42nd street", + "fullTitle": "index.js distanceFromHqInBlocks() calculates distances below 42nd street", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "returns a distance in feet", + "fullTitle": "index.js distanceFromHqInFeet() returns a distance in feet", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "returns a distance in feet", + "fullTitle": "index.js distanceFromHqInFeet() returns a distance in feet", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "calculates distances below 42nd street", + "fullTitle": "index.js distanceFromHqInFeet() calculates distances below 42nd street", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "returns the distance travelled in feet", + "fullTitle": "index.js distanceTravelledInFeet() returns the distance travelled in feet", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "returns a distance in feet", + "fullTitle": "index.js distanceTravelledInFeet() returns a distance in feet", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "returns distance when destination is below distance", + "fullTitle": "index.js distanceTravelledInFeet() returns distance when destination is below distance", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "gives customers a free sample", + "fullTitle": "index.js calculatesFarePrice(start, destination) gives customers a free sample", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "charges 2 cents per foot when total feet travelled is between 400 and 2000 (remember the first 400 feet are free!)", + "fullTitle": "index.js calculatesFarePrice(start, destination) charges 2 cents per foot when total feet travelled is between 400 and 2000 (remember the first 400 feet are free!)", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "charges 25 dollars for a distance over 2000 feet", + "fullTitle": "index.js calculatesFarePrice(start, destination) charges 25 dollars for a distance over 2000 feet", + "duration": 0, + "currentRetry": 0, + "err": {} + }, + { + "title": "does not allow rides over 2500 feet", + "fullTitle": "index.js calculatesFarePrice(start, destination) does not allow rides over 2500 feet", + "duration": 0, + "currentRetry": 0, + "err": {} + } + ] +} \ No newline at end of file diff --git a/index.js b/index.js index 0db6949168..5f6f44d338 100644 --- a/index.js +++ b/index.js @@ -1 +1,25 @@ -// Code your solution in this file! +function distanceFromHqInBlocks(pickupLocation) { + return Math.abs(42 - pickupLocation); +} +function distanceFromHqInFeet(feet) { + return Math.abs(42 - feet) * 264; +} +function distance (start, destination) { + return Math.abs(start - destination) +} +function distanceTravelledInFeet(start, destination) { + const distanceInBlocks = distance(start, destination) + return distanceInBlocks * 264; +} +function calculatesFarePrice(start, destination) { + const travelDistance = distanceTravelledInFeet(start, destination) + if (travelDistance <= 400) { + return 0; + } else if (travelDistance <= 2000) { + return (travelDistance - 400) * 0.02; + } else if (travelDistance <= 2500) { + return 25; + } else { return 'cannot travel that far' + } +}; + \ No newline at end of file diff --git a/package.json b/package.json index 609f08d9aa..e11e9e237e 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "JavaScript Basics Functions Lab for Learn.co", "main": "index.js", "scripts": { - "test": "mocha --timeout 5000 -R mocha-multi --reporter-options spec=-,json=.results.json" + "test": "mocha --timeout 5000 -R mocha-multi --reporter-options spec=-,json=.results.json -b" }, "repository": { "type": "git",