forked from learn-co-curriculum/phase-1-functions-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (32 loc) · 1.39 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function distanceFromHqInBlocks(location) {
const hq = 42; // HQ is located at 42nd street
return Math.abs(location - hq); // Return the absolute difference between the location and Hq
}
function distanceFromHqInBlocks(location) {
const hq = 42; // HQ is located at 42nd street
return Math.abs(location - hq); // Return the absolute difference between the location and Hq
}
function distanceFromHqInFeet(location) {
const blocks = distanceFromHqInBlocks(location);
const feetPerBlock = 264; // There are 264 feet per block in Manhattan
return blocks * feetPerBlock;
}
function distanceTravelledInFeet(start, end) {
const distanceInBlocks = Math.abs(end - start);
const feetPerBlock = 264; // There are 264 feet per block in Manhattan
return distanceInBlocks * feetPerBlock;
}
function calculatesFarePrice(start, destination) {
const distance = distanceTravelledInFeet(start, destination);
if (distance <= 400) {
return 0; // Free sample
} else if (distance > 400 && distance <= 2000) {
const distanceAfterFreeSample = distance - 400;
const fare = distanceAfterFreeSample * 0.02;
return fare;
} else if (distance > 2000 && distance <= 2500) {
return 25; // Flat fare of $25 for distance between 2000 and 2500 feet
} else {
return 'cannot travel that far'; // Distance over 2500 feet is not allowed
}
}