Mathias Bakken - #16
Conversation
…nclear on what to do with that variable.
…nclear on what to do with that variable.
| // ==== Challenge 1 ==== | ||
| // 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*` ); | ||
| console.log(`Car 33 is a ${inventory[32].car_year} ${inventory[32].car_make} ${inventory[32].car_model}`); |
There was a problem hiding this comment.
👍 Great job, doing this in place is the best way to approach this problem.
| let lastCar = 0; | ||
| console.log(); | ||
| let lastCar = inventory[inventory.length - 1]; | ||
| console.log(`${lastCar.car_make} ${lastCar.car_model}`); |
There was a problem hiding this comment.
Consider using more descriptive console logs in the future, Like so:
console.log(`The last item in the list is a: ${lastCar.car_make} ${lastCar.car_model}`);
| oldCars.push(carYears[i]) | ||
| } | ||
| } | ||
| console.log(oldCars.length); |
There was a problem hiding this comment.
A bit more descriptive console.log in order to identify the output later would be like this:
console.log('There is a total of: ', oldCars.length, ' cars older than the year 2000')
| BMWAndAudi.push(inventory[i]); | ||
| } | ||
| } | ||
| console.log(BMWAndAudi); No newline at end of file |
There was a problem hiding this comment.
Good Job using stringify and the II operator.
Perhaps utilizing some more of the stringify functionality a very nice list can be displayed.
console.log(JSON.stringify(BMWAndAudi, console.log('List of BMW and Audi Cars:'), '\t'));
On the code above I used the stringify function, and passed in a console.log to create a header, and used '\t' the tab character to separate each line with a tab.
| @@ -2,27 +2,33 @@ const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum']; | |||
|
|
|||
There was a problem hiding this comment.
You have a very good understanding of callbacks 💯
| // Give Kennan the ability to say "Hello, my name is Kennan!" Use the console.log provided as a hint. | ||
| // console.log(kennan.speak()); | ||
| interns[1].speak = function () { | ||
| return "Hello my name is Kennan!"; |
There was a problem hiding this comment.
Utilizing a bit more intricate method the keyword 'this' can be used to refer to the inter object also like so:
return ("Hello my name is " + this.name + "!");
Also we can make the speak function be in charge of console.log as well like so:
// Declaring a function to be used for every intern to speak.
function speak() {
console.log('Hello my name is ' + this.name + '!');
}
interns[1].speak = speak;
// The same function can then be reused in for every other intern.
interns[2].speak = speak;
interns[3].speak = speak;
interns[4].speak = speak;
interns[5].speak = speak;
No description provided.