Skip to content

Commit 0425ff1

Browse files
Task 1: arrays.js completed
1 parent 31b6ef9 commit 0425ff1

1 file changed

Lines changed: 32 additions & 7 deletions

File tree

‎assignments/arrays.js‎

Lines changed: 32 additions & 7 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+
console.log(`Car 33 is a ${inventory[32].car_year} ${inventory[32].car_make} ${inventory[32].car_model}` );
6767

6868

6969

7070
// ==== Challenge 2 ====
7171
// 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();
72+
let lastCar = inventory[inventory.length -1];
73+
console.log(`${lastCar.car_year} ${lastCar.car_make} ${lastCar.car_model}`);
7474

7575
// ==== Challenge 3 ====
7676
// 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
7777
let carModels = [];
78-
console.log();
78+
let index = 0;
79+
inventory.forEach(function (element){
80+
carModels.push(inventory[index].car_model);
81+
index++;
82+
});
83+
console.log(carModels.sort());
7984

8085
// ==== Challenge 4 ====
8186
// 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.
8287
let carYears = [];
83-
console.log();
88+
index = 0;
89+
inventory.forEach(function(element){
90+
carYears.push(inventory[index].car_year);
91+
index++;
92+
});
93+
console.log(carYears);
8494

8595
// ==== Challenge 5 ====
8696
// 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.
8797
let oldCars =[];
88-
console.log();
98+
index = 0;
99+
carYears.forEach(function(element){
100+
if(element > 2000){
101+
oldCars.push(carYears[index]);
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+
index = 0;
110+
inventory.forEach(function(element){
111+
if(Object.values(element).includes("BMW") || Object.values(element).includes("Audi")){
112+
BMWAndAudi.push(inventory[index].car_year);
113+
BMWAndAudi.push(inventory[index].car_make);
114+
BMWAndAudi.push(inventory[index].car_model);
115+
}
116+
index++;
117+
});
118+
console.log(JSON.stringify(BMWAndAudi));
94119

95120

96121

0 commit comments

Comments
 (0)