-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3tada6_11.js
More file actions
57 lines (43 loc) · 1.32 KB
/
3tada6_11.js
File metadata and controls
57 lines (43 loc) · 1.32 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//6. vehicle
var vehicle = ["motorbike", "caravan", "bike", "scooter", "car", "truck"];
var age;
console.log(vehicle[5]);
function vehicleList(color, index, age){
for(i =0; i<vehicle.length; i++)
if(index === i ){
(age => 2) ? console.log("A " + color + " new " + age) : console.log("A " + color + " used " + age);
}
}
vehicleList("pink", 0, vehicle[1]);
//7. list of vehicles//
console.log(vehicle);
//8 3rd element//
console.log(vehicle[2]);
//9.function vehicle//
function getVehicle(color, index, age){
for(i =0; i<vehicle.length; i++)
if(index === i ){
(age < 1) ? console.log("A " + color + " new " + age) : console.log("A " + color + " used " + age);
}
}
getVehicle("Green", 2, vehicle[3]);
//10. advertisement//
function garage(){
var advertisement = ("At Amazing Joe's Garage, we service: ");
var last_item = vehicle[vehicle.length - 1];
for (i = 0; i < vehicle.length; i++){
if (i === 0) {
console.log((advertisement) + vehicle[0] + "s,");
} else if (i < vehicle.length - 1){
console.log(vehicle[i] + "s,");
} else {
console.log("and " + (last_item) + "s.");
}
}
}
garage();
/* 11. What if you add one more vehicle to the list,
can you have that added to the advertisement
without changing the code for question 10?/*/
vehicle.push("rickshaw");
garage();