Skip to content

Commit 5fefb6d

Browse files
committed
completed arrays.js
1 parent 335d554 commit 5fefb6d

1 file changed

Lines changed: 35 additions & 10 deletions

File tree

‎assignments/arrays.js‎

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,59 @@ 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*` );
66+
for(car in inventory){
67+
if(inventory[car]["id"] === 33){
68+
console.log(`Car ${inventory[car]["id"]} is a ${inventory[car]['car_year']} ${inventory[car]['car_make']} ${inventory[car]['car_model']}`)
69+
}
70+
}
71+
6772

6873

6974

7075
// ==== Challenge 2 ====
7176
// 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();
77+
let lastCar = inventory.length;
78+
for(car in inventory){
79+
if(inventory[car]["id"] === lastCar){
80+
console.log(`The last car is a ${inventory[car]['car_make']} ${inventory[car]['car_model']}`)
81+
}
82+
}
7483

7584
// ==== Challenge 3 ====
7685
// 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
7786
let carModels = [];
78-
console.log();
87+
for (car in inventory){
88+
// console.log(inventory[car]["car_model"])
89+
let model = inventory[car]["car_model"].toLowerCase();
90+
carModels.push(model);
91+
}
92+
carModels = carModels.sort();
93+
console.log(carModels);
7994

8095
// ==== Challenge 4 ====
8196
// 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.
8297
let carYears = [];
83-
console.log();
98+
for(car in inventory){
99+
carYears.push(inventory[car]['car_year'])
100+
}
101+
console.log(carYears);
84102

85103
// ==== Challenge 5 ====
86104
// 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.
87105
let oldCars =[];
88-
console.log();
106+
for(car in inventory){
107+
if (inventory[car]['car_year'] < 2000){
108+
oldCars.push(inventory[car]['car_year'])
109+
};
110+
}
111+
console.log(oldCars.length);
89112

90113
// ==== Challenge 6 ====
91114
// 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.
92115
let BMWAndAudi =[];
93-
console.log();
94-
95-
96-
116+
for (car in inventory) {
117+
if (inventory[car]["car_make"] === 'BMW' ||inventory[car]["car_make"]=== 'Audi'){
118+
BMWAndAudi.push(inventory[car]);
119+
}
120+
}
121+
console.log(JSON.stringify(BMWAndAudi));

0 commit comments

Comments
 (0)