You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: assignments/arrays.js
+23-6Lines changed: 23 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -63,12 +63,16 @@ let inventory = [{"id":1,"car_make":"Lincoln","car_model":"Navigator","car_year"
63
63
64
64
// ==== Challenge 1 ====
65
65
// The dealer can't recall the information for a car with an id of 33 on his lot. Help the dealer find out which car has an id of 33 by logging the car's year, make, and model in the console log provided to you below:
66
-
console.log(`Car 33 is a *car year goes here* *car make goes here* *car model goes here*`);
66
+
letid33=inventory.find(function(car){
67
+
returncar.id===33;
68
+
});
69
+
70
+
console.log("Car 33 is a",id33.car_year,id33.car_make,id33.car_model);
67
71
68
72
// ==== Challenge 2 ====
69
73
// The dealer needs the information on the last car in their inventory. What is the make and model of the last car in the inventory? Log the make and model into the console.
70
-
letlastCar=0;
71
-
console.log();
74
+
letlastCar=inventory[inventory.length-1];
75
+
console.log("Last car in inventory:",lastCar.car_make,lastCar.car_model);
72
76
73
77
// ==== Challenge 3 ====
74
78
// The marketing team wants the car models listed alphabetically on the website. Sort all the car model names into alphabetical order and log the results in the console
@@ -78,17 +82,30 @@ console.log();
78
82
// ==== Challenge 4 ====
79
83
// The accounting team needs all the years from every car on the lot. Create a new array from the dealer data containing only the car years and log the result in the console.
80
84
letcarYears=[];
81
-
console.log();
85
+
for(leti=0;i<inventory.length;i++){
86
+
carYears.push(inventory[i].car_year);
87
+
}
88
+
console.log("List of car years in inventory:",carYears);
82
89
83
90
// ==== Challenge 5 ====
84
91
// The car lot manager needs to find out how many cars are older than the year 2000. Using the carYears array you just created, find out how many cars were made before the year 2000 by populating the array oldCars and logging it's length.
85
92
letoldCars=[];
86
-
console.log();
93
+
for(leti=0;i<carYears.length;i++){
94
+
if(carYears[i]<2000){
95
+
oldCars.push(carYears[i]);
96
+
}
97
+
}
98
+
console.log("Number of cars in inventory older than 2000:",oldCars.length);
87
99
88
100
// ==== Challenge 6 ====
89
101
// A buyer is interested in seeing only BMW and Audi cars within the inventory. Return an array that only contains BMW and Audi cars. Once you have populated the BMWAndAudi array, use JSON.stringify() to show the results of the array in the console.
0 commit comments