You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit fd3a7c2
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: assignments/arrays.js
+39-7Lines changed: 39 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -63,32 +63,64 @@ let inventory = [{"id":1,"car_make":"Lincoln","car_model":"Navigator","car_year"
63
63
64
64
// ==== Challenge 1 ====
65
65
// 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}`);
67
67
68
68
// ==== Challenge 2 ====
69
69
// 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.
// 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
75
75
letcarModels=[];
76
-
console.log();
76
+
for(leti=0;i<inventory.length;i++){
77
+
carModels.push(inventory[i].car_model);
78
+
}
79
+
//sorts car_model values of inventory alphabetically and console.logs the result
80
+
console.log(carModels.sort());
81
+
82
+
//verifies that alphabetically sorted array is same length as inventory array to ensure there are no missing entries
83
+
console.log(carModels.length===inventory.length);
84
+
85
+
86
+
77
87
78
88
// ==== Challenge 4 ====
79
89
// 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.
80
90
letcarYears=[];
81
-
console.log();
91
+
92
+
//adds year of each inventory item to carYears
93
+
for(leti=0;i<inventory.length;i++){
94
+
carYears.push(inventory[i].car_year);
95
+
}
96
+
97
+
//logs the array of years
98
+
console.log(carYears);
99
+
100
+
//verifies that array is same length as inventory array to ensure there are no missing entries
101
+
console.log(carYears.length===inventory.length);
82
102
83
103
// ==== Challenge 5 ====
84
104
// 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.
85
105
letoldCars=[];
86
-
console.log();
106
+
107
+
for(leti=0;i<carYears.length;i++){
108
+
if(carYears[i]>2000){
109
+
oldCars.push(carYears[i]);
110
+
}
111
+
}
112
+
console.log(oldCars.length);
87
113
88
114
// ==== Challenge 6 ====
89
-
// 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.
115
+
// A buyer is interested in seeing only BMW and Audi cars within the inventory.
116
+
// Return an array that only contains BMW and Audi cars.
117
+
// Once you have populated the BMWAndAudi array, use JSON.stringify() to show the results of the array in the console.
0 commit comments