Skip to content

Commit 5d452c4

Browse files
authored
Create vehicle-purchase.js
includes concepts of "Conditionals" and "Comparisons".
1 parent 004c1a3 commit 5d452c4

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

vehicle-purchase.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Determines whether or not you need a licence to operate a certain kind of vehicle.
3+
*
4+
* @param {string} kind
5+
* @returns {boolean} whether a license is required
6+
*/
7+
export function needsLicense(kind) {
8+
return ((kind === "car") || (kind === "truck"));
9+
}
10+
/**
11+
* Helps choosing between two options by recommending the one that
12+
* comes first in dictionary order.
13+
*
14+
* @param {string} option1
15+
* @param {string} option2
16+
* @returns {string} a sentence of advice which option to choose
17+
*/
18+
export function chooseVehicle(option1, option2) {
19+
if (option1 > option2){
20+
return option2 + " is clearly the better choice.";
21+
} else{
22+
return option1 + " is clearly the better choice.";
23+
}
24+
}
25+
/**
26+
* Calculates an estimate for the price of a used vehicle in the dealership
27+
* based on the original price and the age of the vehicle.
28+
*
29+
* @param {number} originalPrice
30+
* @param {number} age
31+
* @returns {number} expected resell price in the dealership
32+
*/
33+
export function calculateResellPrice(originalPrice, age) {
34+
if (age < 3) {
35+
return 0.8 * originalPrice;
36+
} else if (age>10) {
37+
return 0.5 * originalPrice;
38+
} else {
39+
return 0.7 * originalPrice;
40+
}
41+
}

0 commit comments

Comments
 (0)