Skip to content

Commit 309b0fd

Browse files
committed
1 parent 1e84956 commit 309b0fd

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

assignments/arrays.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let inventory = [{"id":1,"car_make":"Lincoln","car_model":"Navigator","car_year"
77
{"id":3,"car_make":"Land Rover","car_model":"Defender Ice Edition","car_year":2010},
88
{"id":4,"car_make":"Honda","car_model":"Accord","car_year":1983},
99
{"id":5,"car_make":"Mitsubishi","car_model":"Galant","car_year":1990},
10-
{"id":6,"car_make":"Audi","car_model":"Riolet","car_year":1995},
10+
{"id":6,"car_make":"Audi","car_model":"riolet","car_year":1995},
1111
{"id":7,"car_make":"Smart","car_model":"Fortwo","car_year":2009},
1212
{"id":8,"car_make":"Audi","car_model":"4000CS Quattro","car_year":1987},
1313
{"id":9,"car_make":"Ford","car_model":"Windstar","car_year":1996},
@@ -94,16 +94,27 @@ console.log(carYears)
9494
// // ==== Challenge 5 ====
9595
// // 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.
9696
let oldCars = [];
97-
for (let i=0;i<inventory.length;i++) {
98-
oldCars[i]= inventory[i].car_year;
97+
for (let i=0; i < carYears.length ;i++) {
98+
if (carYears[i] < 2000) {
99+
oldCars.push(inventory[i]);
100+
}
101+
99102
}
100-
101-
103+
console.log(oldCars);
102104

103105
// // ==== Challenge 6 ====
104106
// // 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.
105-
let BMWAndAudi =[];
106-
console.log();
107+
let BMWAndAudi = [];
108+
109+
for (let i=0; i<inventory.length; i++) {
110+
if (inventory[i].car_make === "BMW") {
111+
BMWAndAudi.push(inventory[i]);
112+
}
113+
if (inventory[i].car_make === "Audi") {
114+
BMWAndAudi.push(inventory[i]);
115+
}
116+
}
117+
console.log(JSON.stringify(BMWAndAudi));
107118

108119

109120

0 commit comments

Comments
 (0)