Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9e93e78

Browse files
authored
Update moreJs-6.js
1 - condition's (function) parameter changed as 'age' from 'years'. this way more consistent with lines above. 2- if statement added for the value of 'type' parameter. console logs the vehicle only if it has vehicle type. otherwise logs an warning
1 parent 0887518 commit 9e93e78

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

Week3/moreJs-6.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ Create a function called vehicle, like before,
55
prints 'a blue used car'
66
*/
77

8-
function vehicle (color, type, age){
9-
let types = [' car' , ' motorbike'];
10-
console.log('a ' + color +' ' + condition(age) + types[(type-1)]);
8+
function vehicle(color, type, age) {
9+
let types = [' car', ' motorbike', 'truck', 'bus'];
10+
if (type > 0 && type <= types.length) {
11+
console.log('a ' + color + ' ' + condition(age) + types[type - 1]);
12+
} else {
13+
console.log('!NO SUCH VEHICLE HERE');
14+
}
1115
}
12-
function condition(years){
13-
if (years<2){
14-
return 'new';
15-
} else {
16-
return 'used';
17-
}
16+
function condition(age) {
17+
if (age < 2) {
18+
return 'new ';
19+
} else {
20+
return 'used ';
21+
}
1822
}
19-
vehicle('red' , 1, 3);
23+
vehicle('red', 3, 3);

0 commit comments

Comments
 (0)