5-6-19 Javascript Project - #1
Conversation
…it's clearly a mistake to include
…it. Half an hour of the zoom session and explaining how to use a for-loop, and I knocked out challenges 3, 4, 5, and 6 in less than 30 minutes
OmarSalah95
left a comment
There was a problem hiding this comment.
Great job reaching into stretch here Greg! I can see after our short review you seem to have a much better grasp of the base concepts of how things are working which is great! keep up the great work!
| //the car's year, make, and model in the console log provided to you below: | ||
|
|
||
|
|
||
| console.log("Car 33 is a " + inventory[32].car_model + " made by " + inventory[32].car_make + " and the year is " + inventory[32].car_year); |
There was a problem hiding this comment.
This is hard coding which car and position in the array you are pointing at and it is a no-no. What if the position of that care shifted because another car has been sold?
What you want to do is iterate through each item in the array testing the id key on each object as you do, IF the id matches then you want to return that data.
| //What is the make and model of the last car in the inventory? Log the make and model into the console. | ||
|
|
||
| let lastCar = inventory.length - 1; | ||
| console.log(inventory[lastCar]); |
There was a problem hiding this comment.
Good use of .length reduced by one to target the last item, since arrays start at 0 index and not 1
| newArray.push(inventory[i].car_model) | ||
| } | ||
|
|
||
| console.log(newArray.sort()); |
There was a problem hiding this comment.
Great job breaking this into 2 pieces and just adding the sort to the newArray. I would take another look at more specific naming convention here though. This way it doesn't become confusing.
|
|
||
| let oldCars = []; | ||
| console.log(); | ||
| console.log(carYears[5]) |
|
|
||
| if (inventory[i].car_make === "BMW" || inventory[i].car_make === "Audi") | ||
|
|
||
| BMWAndAudi.push(inventory[i]) |
There was a problem hiding this comment.
Great use of the or Logical Operator || here.
Don't forget to open and close {} after your IF conditional. Inside of that block of code is what will be executed if the if conditions are met.
| // console.log(triple); | ||
|
|
||
| let triple = exampleArray.map((num) => {return num * 3;}); | ||
|
|
There was a problem hiding this comment.
Great job solving this one with .map. since you are using fat arrow syntax you actually don't need the brackets or the return. Fat arrow functions have what is called an implicit return. You could write the map as such
.map((num) => num * 3);
Finished Object.js and function-conversion.js, as well as stretch goals for both.
Not going to do array.js. It's an obvious oversight that it was included, and I'm already furious that I wasted an hour and a half of my time on it. The other two exercises, object.js and functions.js were quite good, and helped deepen my understanding of the material, but array.js was like asking a preschooler to perform physics.