Skip to content

Commit c5d7e18

Browse files
author
AGORA\mjones
committed
array challenge 2 complete
1 parent d269f77 commit c5d7e18

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

assignments/arrays.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,24 @@ 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 inventory[32].car_year inventory[32].car_make inventory[32].car_model`);
6766

68-
console.log("Car 33 is a " + inventory[32].car_year + ' ' + inventory[32].car_make + ' ' + inventory[32].car_model);
67+
console.log("Car 33 is a " + inventory[32].car_year, inventory[32].car_make, inventory[32].car_model);
6968

7069
// ==== Challenge 2 ====
7170
// 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-
const lastCar = inventory[-1];
73-
console.log(lastCar);
71+
const lastCar = inventory[inventory.length -1];
72+
console.log(lastCar.car_make, lastCar.car_model);
7473

7574
// ==== Challenge 3 ====
7675
// 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
77-
78-
7976
let carModels = [];
77+
for (let i = 0; i < inventory.length; i++) {
78+
carModels.push(inventory[i].car_model);
79+
}
8080

81+
carModels.sort();
8182

82-
console.log();
83+
console.log(carModels);
8384

8485
// ==== Challenge 4 ====
8586
// 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.

0 commit comments

Comments
 (0)