Skip to content

Commit fda0504

Browse files
committed
Done with MVP and also stretch goals
1 parent 60e75a6 commit fda0504

3 files changed

Lines changed: 70 additions & 8 deletions

File tree

assignments/arrays.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,45 @@ let sorting = inventory.sort((a, b) => {
9393
return 0;
9494
});
9595
carModels.push(sorting);
96+
console.log('Here is the list of car models');
9697
console.log(carModels);
9798

9899
// ==== Challenge 4 ====
99100
// 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.
100-
let carYears = [];
101-
console.log();
101+
let carYears = inventory.map(x => x.car_year);
102+
console.log('Here is the list of car years');
103+
console.log(carYears);
102104

103105
// ==== Challenge 5 ====
104106
// 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.
105107
let oldCars = [];
106-
console.log();
108+
/*
109+
for(let i = 0; i < carYears.length; i++) {
110+
if (carYears[i] < 2000) {
111+
oldCars.push(carYears[i]);
112+
}
113+
}
114+
*/
115+
116+
carYears.map(x => {
117+
if(x < 2000) {
118+
oldCars.push(x);
119+
}
120+
});
121+
console.log('Here is the list of cars older than the year 2000');
122+
console.log(oldCars);
107123

108124
// ==== Challenge 6 ====
109125
// 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.
110126
let BMWAndAudi = [];
111-
console.log();
127+
128+
inventory.filter(x => {
129+
if(x.car_make === 'BMW' || x.car_make === 'Audi') {
130+
BMWAndAudi.push(x);
131+
}
132+
});
133+
134+
console.log(JSON.stringify(BMWAndAudi));
112135

113136

114137

assignments/function-conversion.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,31 @@
55
// };
66
// myFunction();
77

8+
let myFunction = () => console.log("Function was invoked!");
9+
myFunction();
10+
11+
812
// let anotherFunction = function (param) {
913
// return param;
1014
// };
1115
// anotherFunction("Example");
1216

17+
let anotherFunction = (param) => param;
18+
console.log(anotherFunction("example"));
19+
1320
// let add = function (param1, param2) {
1421
// return param1 + param2;
1522
// };
1623
// add(1,2);
24+
let add = (param1, param2) => param1 + param2;
25+
console.log(add(1,2));
1726

1827
// let subtract = function (param1, param2) {
1928
// return param1 - param2;
2029
// };
2130
// subtract(1,2);
31+
let subtract = (param1, param2) => param1 - param2;
32+
console.log(subtract(1, 2));
2233

2334

2435
// Stretch
@@ -27,4 +38,7 @@
2738
// const triple = exampleArray.map(function (num) {
2839
// return num * 3;
2940
// });
30-
// console.log(triple);
41+
// console.log(triple);
42+
const exampleArray = [1,2,3,4];
43+
const triple = exampleArray.map(num => num * 3);
44+
console.log(triple);

assignments/objects.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,41 @@ console.log(interns[4].multiplyNums(3,4));
9292
// 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
9393
// 4. Give each of the objects the ability to speak their names using the this keyword.
9494

95-
const parent = {}
95+
const parent = {
96+
name: "Susan",
97+
age: 70,
98+
child: {
99+
name: "George",
100+
age: 50,
101+
grandChild: {
102+
name: "Sam",
103+
age: 30,
104+
speak: function() {
105+
return 'Hi I am a grand child, and my name is ' + this.name + '.';
106+
}
107+
},
108+
speak: function() {
109+
return 'Hi I am a child and my name is ' + this.name + '.';
110+
}
111+
},
112+
speak: function() {
113+
return 'Hi I am ' + this.name + '.';
114+
}
115+
116+
}
96117

97118
// Log the parent object's name
119+
console.log(parent.name);
98120

99121
// Log the child's age
122+
console.log(parent.child.name)
100123

101124
// Log the name and age of the grandchild
102-
125+
console.log(parent.child.grandChild.name)
103126
// Have the parent speak
104-
127+
console.log(parent.speak());
105128
// Have the child speak
129+
console.log(parent.child.speak());
106130

107131
// Have the grandchild speak
132+
console.log(parent.child.grandChild.speak());

0 commit comments

Comments
 (0)