Skip to content

Commit 4241897

Browse files
author
Sascha
committed
added in a different solution appraoch to the parent objects.
1 parent 241f64b commit 4241897

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎assignments/arrays.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,14 @@ console.log(oldCars);
9999

100100
// ==== Challenge 6 ====
101101
// 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.
102-
let BMWAndAudi = [];
102+
103+
/* let BMWAndAudi = [];
103104
for (let i = 0; i < inventory.length; i++) {
104105
if (inventory[i].car_make === "BMW" || inventory[i].car_make === "Audi" ){
105106
BMWAndAudi.push(inventory[i]); // 1,2,3,4
106107
}
107-
}
108+
} */
109+
110+
let BMWAndAudi = inventory.filter((el) => el.car_make == "BMW" || el.car_make == "Audi");
108111
console.log(JSON.stringify(BMWAndAudi));
112+

‎assignments/objects.js‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,27 @@ console.log(internFive.multiplyNums(3,4));
9797
// 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
9898
// 4. Give each of the objects the ability to speak their names using the this keyword.
9999

100+
/* Other solution
101+
function person (name, age) {
102+
return {
103+
name: name,
104+
age: age,
105+
speak: function () {
106+
console.log(this.name)
107+
}
108+
};
109+
}
110+
111+
const parent = person("Susan", 70);
112+
parent.child = person("Goerge", 50);
113+
parent.child.grandchild = person("Sam", 30);
114+
115+
parent.speak();
116+
parent.child.speak();
117+
parent.child.grandchild.speak();
118+
*/
119+
120+
100121
const parent = {
101122
name: "Susan",
102123
age: 70,
@@ -111,6 +132,7 @@ const parent = {
111132
}
112133
}
113134

135+
114136
// Log the parent object's name
115137
console.log(parent.name);
116138
// Log the child's age

0 commit comments

Comments
 (0)