Skip to content

Commit c517acc

Browse files
committed
finished challenges 4 and 5 using for loops, if statements and pushing
1 parent 6c00235 commit c517acc

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

assignments/arrays.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,20 @@ console.log(carModels.sort());
8383
// ==== Challenge 4 ====
8484
// 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.
8585
let carYears = [];
86-
console.log();
86+
for(let i = 0; i < inventory.length; i++){
87+
carYears.push(inventory[i].car_year);
88+
}
89+
console.log(carYears);
8790

8891
// ==== Challenge 5 ====
8992
// 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.
9093
let oldCars =[];
91-
console.log();
94+
for(let i = 0; i < inventory.length; i++){
95+
if (2000 - inventory[i].car_year > 0){
96+
oldCars.push(inventory[i].car_year);
97+
}
98+
}
99+
console.log(oldCars.length);
92100

93101
// ==== Challenge 6 ====
94102
// 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)