Initial commit - #1
Conversation
| // 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: | ||
| console.log(`Car 33 is a *car year goes here* *car make goes here* *car model goes here*` ); | ||
| function getCar(id) { | ||
| if (id === -1) { |
There was a problem hiding this comment.
what happens if id === 0? or id === -2?
you could refine this if statement a bit to cover more of these edge cases.
if (id < 1)
| return inventory[inventory.length - 1]; | ||
| } else { | ||
| for (let i = 0; i < inventory.length; i++) { | ||
| if (Object.values(inventory[i])[0] === id) { |
There was a problem hiding this comment.
you're getting the job done, but there is a more direct way to get at this information.
if (inventory[i].id === id)
| const car33 = getCar(33); | ||
| console.log( | ||
| `Car 33 is a ${car33.car_year} ${car33.car_make} ${car33.car_model}` | ||
| ); |
There was a problem hiding this comment.
great job solving this first challenge. writing a function is perfect way to make your code reusable.
| let lastCar = getCar(-1); | ||
| console.log( | ||
| `Last car is a ${lastCar.car_year} ${lastCar.car_make} ${lastCar.car_model}` | ||
| ); |
There was a problem hiding this comment.
ah, now i understand why you wrote that if statement on LINE 78. great job using your function to solve both of these challenges.
| // 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 | ||
| let carModels = []; | ||
| console.log(); | ||
| function sortModels (){ |
There was a problem hiding this comment.
wow. constructing this sort function from scratch is an impressive bit of work. for future reference: JavaScript includes a built-in sort method for arrays which performs a similar logic with a slightly different syntax.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
| let oldCars = []; | ||
| console.log(); | ||
| // let oldCars = carYears.filter() | ||
| console.log(carYears.filter( car_year => car_year < 2000).length); |
There was a problem hiding this comment.
perfect way to solve this in one line.
|
|
||
|
|
||
|
|
||
| let BMWAndAudi = inventory.filter(inventory => inventory.car_make === "BMW" || inventory.car_make === "Audi"); |
There was a problem hiding this comment.
another perfect one-liner.
| console.log(parent.child.age); | ||
|
|
||
| // Log the name and age of the grandchild | ||
| console.log(parent.child.child.name + ", " + parent.child.child.age); |
There was a problem hiding this comment.
this could also be written as a template literal using backticks and interpolated strings.
console.log(`${parent.child.child.name}, ${parent.child.child.age}`);
No description provided.