-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvehicle-purchase.js
More file actions
41 lines (41 loc) · 1.16 KB
/
vehicle-purchase.js
File metadata and controls
41 lines (41 loc) · 1.16 KB
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
36
37
38
39
40
41
/**
* Determines whether or not you need a licence to operate a certain kind of vehicle.
*
* @param {string} kind
* @returns {boolean} whether a license is required
*/
export function needsLicense(kind) {
return ((kind === "car") || (kind === "truck"));
}
/**
* Helps choosing between two options by recommending the one that
* comes first in dictionary order.
*
* @param {string} option1
* @param {string} option2
* @returns {string} a sentence of advice which option to choose
*/
export function chooseVehicle(option1, option2) {
if (option1 > option2){
return option2 + " is clearly the better choice.";
} else{
return option1 + " is clearly the better choice.";
}
}
/**
* Calculates an estimate for the price of a used vehicle in the dealership
* based on the original price and the age of the vehicle.
*
* @param {number} originalPrice
* @param {number} age
* @returns {number} expected resell price in the dealership
*/
export function calculateResellPrice(originalPrice, age) {
if (age < 3) {
return 0.8 * originalPrice;
} else if (age>10) {
return 0.5 * originalPrice;
} else {
return 0.7 * originalPrice;
}
}