Skip to content

Commit 2df0343

Browse files
arrays.js Done
1 parent 8a55e7e commit 2df0343

1 file changed

Lines changed: 29 additions & 8 deletions

File tree

‎assignments/arrays.js‎

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,55 @@ let inventory = [{"id":1,"car_make":"Lincoln","car_model":"Navigator","car_year"
6363

6464
// ==== Challenge 1 ====
6565
// 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*` );
67-
6866

67+
for(let i = 0; i < inventory.length; i++) {
68+
if(inventory[i].id === 33) {
69+
console.log(`Car 33 is a ${inventory[i].car_year} ${inventory[i].car_make} ${inventory[i].car_model}`);
70+
//33,"car_make":"Jeep","car_model":"Wrangler","car_year":2011},
71+
}
72+
}
6973

7074
// ==== Challenge 2 ====
7175
// 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.
72-
let lastCar = 0;
73-
console.log();
76+
let lastCar = inventory[inventory.length - 1];
77+
console.log(lastCar);
7478

7579
// ==== Challenge 3 ====
7680
// 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
7781
let carModels = [];
78-
console.log();
82+
for(let i = 0; i < inventory.length; i++) {
83+
carModels.push(inventory[i].car_model);
84+
}
85+
86+
console.log(carModels.sort());
7987

8088
// ==== Challenge 4 ====
8189
// 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.
8290
let carYears = [];
83-
console.log();
91+
for(let i = 0; i < inventory.length; i++) {
92+
carYears.push(inventory[i].car_year);
93+
}
94+
console.log(carYears);
8495

8596
// ==== Challenge 5 ====
8697
// 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.
8798
let oldCars =[];
88-
console.log();
99+
for(let i = 0; i < carYears.length; i++) {
100+
if(carYears[i] < 2000) {
101+
oldCars.push(carYears[i]);
102+
}
103+
}
104+
console.log(oldCars.length);
89105

90106
// ==== Challenge 6 ====
91107
// 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.
92108
let BMWAndAudi =[];
93-
console.log();
109+
for(let i = 0; i < inventory.length; i++) {
110+
if(inventory[i].car_model === "BMW" || inventory[i].car_model === "Audi") {
111+
BMWAndAudi.push(JSON.stringify(inventory[i]));
112+
}
113+
}
114+
console.log(BMWAndAudi);
94115

95116

96117

0 commit comments

Comments
 (0)