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
Copy file name to clipboardExpand all lines: assignments/arrays.js
+72-7Lines changed: 72 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -77,28 +77,93 @@ let inventory = [
77
77
// 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:
78
78
console.log(`Car 33 is a *car year goes here* *car make goes here* *car model goes here*`);
79
79
80
+
for(leti=0;i<inventory.length;i++){
81
+
if(inventory[i].id===33){
82
+
console.log(`Carr 33 is a ${inventory[i].car_year}${inventory[i].car_make}${inventory[i].car_model}`)
83
+
}
84
+
}
85
+
86
+
// Stretch for challenge 1
87
+
inventory.forEach(car=>{
88
+
if(car.id===33){
89
+
console.log(`Carr 33 is a ${car.car_year}${car.car_make}${car.car_model}`)
90
+
}
91
+
})
92
+
80
93
// ==== Challenge 2 ====
81
94
// 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.
82
-
letlastCar=0;
83
-
console.log();
95
+
letlastCar=inventory[inventory.length-1];
96
+
console.log(`The last car is a ${lastCar.car_make}${lastCar.car_model}`);
84
97
85
98
// ==== Challenge 3 ====
86
99
// 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
// 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.
// 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.
// 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.
// Once your objects are created, log out the following requests from HR into the console:
25
58
26
59
// Mitzi's name
27
-
60
+
console.log(mitzi.name)
28
61
// Kennan's ID
29
-
62
+
console.log(kennan.name)
30
63
// Keven's email
31
-
64
+
console.log(keven.name)
32
65
// Gannie's name
33
-
66
+
console.log(gannie.name)
34
67
// Antonietta's Gender
68
+
console.log(antonietta.name)
35
69
36
70
// ==== Challenge 3: Object Methods ====
37
71
// Give Kennan the ability to say "Hello, my name is Kennan!" Use the console.log provided as a hint.
38
-
// console.log(kennan.speak());
72
+
kennan.speak=function(){
73
+
return`Hello, my name is ${this.name}!`
74
+
}
75
+
console.log(kennan.speak());
39
76
40
77
// Antonietta loves math, give her the ability to multiply two numbers together and return the product. Use the console.log provided as a hint.
41
-
//console.log(antonietta.multiplyNums(3,4));
78
+
antonietta.multiplyNums=function(num1,num2){
79
+
returnnum1*num2
80
+
}
81
+
console.log(antonietta.multiplyNums(3,4));
42
82
43
83
// === Great work! === Head over to the the arrays.js. You may come back and attempt the Stretch Challenge once you have completed the challenges in arrays.js and function-conversion.js.
44
84
@@ -49,16 +89,37 @@ const example = {
49
89
// 3. Nest a grandchild object in the child object with properties for name and age. The name will be Sam and the age will be 30
50
90
// 4. Give each of the objects the ability to speak their names using the this keyword.
0 commit comments