Skip to content

Commit be142f6

Browse files
committed
arrays challenge 3, 4 and 5
1 parent 454a2d4 commit be142f6

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

assignments/arrays.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,28 @@ console.log(lastCar.car_make + " " + lastCar.car_model);
8888
// ==== Challenge 3 ====
8989
// 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
9090
let carModels = [];
91-
console.log();
91+
for (let i = 0; i < inventory.length; i++) {
92+
carModels.push(inventory[i].car_model)
93+
}
94+
console.log(carModels.sort());
9295

9396
// ==== Challenge 4 ====
9497
// 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.
9598
let carYears = [];
96-
console.log();
99+
for (let i = 0; i < inventory.length; i++) {
100+
carYears.push(inventory[i].car_year)
101+
}
102+
console.log(carYears);
97103

98104
// ==== Challenge 5 ====
99105
// 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.
100106
let oldCars = [];
101-
console.log();
107+
for (let i = 0; i < inventory.length; i++) {
108+
if (carYears[i] <= 2000) {
109+
oldCars.push(carYears[i]);
110+
}
111+
}
112+
console.log(oldCars.length);
102113

103114
// ==== Challenge 6 ====
104115
// 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

Comments
 (0)