Skip to content

Commit 183b3df

Browse files
author
Sascha
committed
polished a if statement with a ternary operator
1 parent 6e253c2 commit 183b3df

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

assignments/arrays.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,16 @@ console.log(carYears);
9090
// ==== Challenge 5 ====
9191
// 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.
9292
let oldCars = [];
93-
for (let i = 0; i < inventory.length; i++) {
93+
94+
/* for (let i = 0; i < inventory.length; i++) {
9495
if (inventory[i].car_year < 2000){
9596
oldCars.push(inventory[i].car_year); // 1,2,3,4
9697
}
98+
} */
99+
for (let i = 0; i < inventory.length; i++) {
100+
inventory[i].car_year < 2000 ? oldCars.push(inventory[i].car_year) : null;
97101
}
102+
98103
console.log(oldCars);
99104

100105
// ==== Challenge 6 ====
@@ -108,5 +113,4 @@ for (let i = 0; i < inventory.length; i++) {
108113
} */
109114

110115
let BMWAndAudi = inventory.filter((el) => el.car_make == "BMW" || el.car_make == "Audi");
111-
console.log(JSON.stringify(BMWAndAudi));
112-
116+
console.log(JSON.stringify(BMWAndAudi));

0 commit comments

Comments
 (0)