Skip to content

Commit fd3a7c2

Browse files
committed
solves arrays.js problems
1 parent 86fe720 commit fd3a7c2

7 files changed

Lines changed: 265 additions & 13 deletions

File tree

‎.idea/JavaScript-I.iml‎

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/misc.xml‎

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/modules.xml‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/vcs.xml‎

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/workspace.xml‎

Lines changed: 188 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎README.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
**Follow these steps to set up and work on your project:**
88

9-
* [ ] Create a forked copy of this project.
10-
* [ ] Add your project manager as collaborator on Github.
11-
* [ ] Clone your OWN version of the repository (Not Lambda's by mistake!).
12-
* [ ] Create a new branch: git checkout -b `<firstName-lastName>`.
13-
* [ ] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
14-
* [ ] Push commits: git push origin `<firstName-lastName>`.
9+
* [X] Create a forked copy of this project.
10+
* [X] Add your project manager as collaborator on Github.
11+
* [X] Clone your OWN version of the repository (Not Lambda's by mistake!).
12+
* [X] Create a new branch: git checkout -b `<firstName-lastName>`.
13+
* [X] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
14+
* [X] Push commits: git push origin `<firstName-lastName>`.
1515

1616
**Follow these steps for completing your project.**
1717

‎assignments/arrays.js‎

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,32 +63,64 @@ 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
// ==== Challenge 2 ====
6969
// 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.
7070
let lastCar = 0;
71-
console.log();
71+
console.log(`${inventory[lastCar].car_make} ${inventory[lastCar].car_model}`);
7272

7373
// ==== Challenge 3 ====
7474
// 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
7575
let carModels = [];
76-
console.log();
76+
for(let i = 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+
7787

7888
// ==== Challenge 4 ====
7989
// 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.
8090
let carYears = [];
81-
console.log();
91+
92+
//adds year of each inventory item to carYears
93+
for(let i = 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);
82102

83103
// ==== Challenge 5 ====
84104
// 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.
85105
let oldCars = [];
86-
console.log();
106+
107+
for(let i = 0; i < carYears.length; i++){
108+
if(carYears[i] > 2000) {
109+
oldCars.push(carYears[i]);
110+
}
111+
}
112+
console.log(oldCars.length);
87113

88114
// ==== 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.
90118
let BMWAndAudi = [];
91-
console.log();
119+
for(let i = 0; i < inventory.length; i++) {
120+
if(inventory[i].car_make === "BMw" || inventory[i].car_make === "Audi") {
121+
BMWAndAudi.push(inventory[i]);
122+
} }
123+
console.log(JSON.stringify(BMWAndAudi));
92124

93125

94126

0 commit comments

Comments
 (0)