Skip to content

Commit e3e8b39

Browse files
committed
Arrays File Commit
1 parent 335d554 commit e3e8b39

1 file changed

Lines changed: 28 additions & 10 deletions

File tree

assignments/arrays.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,52 @@ 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-
66+
//console.log(`Car 33 is a *car year goes here* *car make goes here* *car model goes here*` );
67+
for (let i = 0; i < inventory.length; i++) {
68+
if (inventory.id[i] === 33) {
69+
console.log('Car 33 is a', inventory[i].car_year, inventory[i][car_make], inventory[i].car_model);
70+
}
71+
}
6872

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.
7276
let lastCar = 0;
73-
console.log();
77+
console.log(inventory[length-1][car_make], inventory[length-1][car_model]);
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+
carModels.sort();
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 < inventory.length; i++) {
100+
if (inventory[i].car_year < 2000) {
101+
oldCars.push(inventory[i].car_year);
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();
94-
95-
96-
109+
for (let i = 0; i < inventory.length; i++) {
110+
if (inventory[i].car_make === 'BMW' || inventory[i].car_make === 'Audi') {
111+
BMWAndAudi.push(inventory[i]);
112+
}
113+
}
114+
console.log(JSON.stringify(BMWAndAudi));

0 commit comments

Comments
 (0)