-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvehicle-purchase.js
50 lines (47 loc) · 1.37 KB
/
vehicle-purchase.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// @ts-check
//
// The line above enables type checking for this file. Various IDEs interpret
// the @ts-check directive. It will give you helpful autocompletion when
// implementing this exercise.
/**
* 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" ? true : false;
}
/**
* 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 originalPrice * 0.8
} else if (age >= 3 && age <= 10) {
return originalPrice * 0.7
} else {
return originalPrice * 0.5
};
}