Skip to content

Commit 9cec4d9

Browse files
Merge pull request #1 from sofialevin/sofia-levin
Sofia levin: Stretch
2 parents 86fe720 + 039161b commit 9cec4d9

3 files changed

Lines changed: 142 additions & 29 deletions

File tree

‎assignments/arrays.js‎

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,32 +63,59 @@ let inventory = [{"id":1,"car_make":"Lincoln","car_model":"Navigator","car_year"
6363

6464
// ==== Challenge 1 ====
6565
// 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:
66-
console.log(`Car 33 is a *car year goes here* *car make goes here* *car model goes here*` );
66+
67+
for (let i = 0; i < inventory.length; i++) {
68+
if (inventory[i]['id'] === 33) {
69+
console.log('Car 33 is a ' + inventory[i]['car_year'] + ' ' + inventory[i]['car_make'] + ' ' + inventory[i]['car_model'] + '.');
70+
}
71+
}
6772

6873
// ==== Challenge 2 ====
6974
// 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.
7075
let lastCar = 0;
71-
console.log();
76+
lastCar = inventory[inventory.length - 1];
77+
console.log(lastCar.car_make + ' ' + lastCar.car_model + '.');
7278

7379
// ==== Challenge 3 ====
7480
// 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
7581
let carModels = [];
76-
console.log();
82+
83+
for (let i = 0; i < inventory.length; i++) {
84+
carModels.push(inventory[i]['car_model']);
85+
}
86+
87+
console.log(carModels.sort());
7788

7889
// ==== Challenge 4 ====
7990
// 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.
8091
let carYears = [];
81-
console.log();
92+
93+
for (let i = 0; i < inventory.length; i++) {
94+
carYears.push(inventory[i]['car_year']);
95+
}
96+
97+
console.log(carYears);
8298

8399
// ==== Challenge 5 ====
84100
// 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.
85101
let oldCars = [];
86-
console.log();
102+
103+
for (let i = 0; i < carYears.length; i++) {
104+
if (carYears[i] < 2000) {
105+
oldCars.push(inventory[i]);
106+
}
107+
}
108+
109+
console.log(oldCars.length);
87110

88111
// ==== Challenge 6 ====
89112
// 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.
90113
let BMWAndAudi = [];
91-
console.log();
92-
93114

115+
for (let i = 0; i < inventory.length; i++) {
116+
if (inventory[i]['car_make'] === 'Audi' || inventory[i]['car_make'] === 'BMW') {
117+
BMWAndAudi.push(inventory[i])
118+
}
119+
}
94120

121+
console.log(JSON.stringify(BMWAndAudi));

‎assignments/function-conversion.js‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
// Take the commented ES5 syntax and convert it to ES6 arrow Syntax
22

3-
// let myFunction = function () {
4-
// console.log("Function was invoked!");
5-
// };
6-
// myFunction();
3+
let myFunction = () => {
4+
console.log("Function was invoked!");
5+
};
6+
myFunction();
77

8-
// let anotherFunction = function (param) {
9-
// return param;
10-
// };
11-
// anotherFunction("Example");
8+
let anotherFunction = (param) => {
9+
return param;
10+
};
11+
anotherFunction("Example");
1212

13-
// let add = function (param1, param2) {
14-
// return param1 + param2;
15-
// };
16-
// add(1,2);
13+
let add = (param1, param2) => {
14+
return param1 + param2;
15+
};
16+
add(1,2);
1717

18-
// let subtract = function (param1, param2) {
19-
// return param1 - param2;
20-
// };
21-
// subtract(1,2);
18+
let subtract = (param1, param2) => {
19+
return param1 - param2;
20+
};
21+
subtract(1,2);
2222

2323

2424
// Stretch
2525

26-
// exampleArray = [1,2,3,4];
27-
// const triple = exampleArray.map(function (num) {
28-
// return num * 3;
29-
// });
30-
// console.log(triple);
26+
exampleArray = [1,2,3,4];
27+
const triple = exampleArray.map((num) => {
28+
return num * 3;
29+
});
30+
console.log(triple);

‎assignments/objects.js‎

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,81 @@ const example = {
1919

2020
// Write your intern objects here:
2121

22+
const student1 = {
23+
"id": 1,
24+
"name": "Mitzi",
25+
"email": "mmelloy0@psu.edu",
26+
"gender": "F"
27+
}
28+
29+
const student2 = {
30+
"id": 2,
31+
"name": "Kennan",
32+
"email": "kdiben1@tinypic.com",
33+
"gender": "M",
34+
"speak": function() {
35+
return "Hello, my name is Kennan!";
36+
}
37+
}
38+
39+
const student3 = {
40+
"id": 3,
41+
"name": "Keven",
42+
"email": "kmummery2@wikimedia.org",
43+
"gender": "M"
44+
}
45+
46+
const student4 = {
47+
"id": 4,
48+
"name": "Gannie",
49+
"email": "gmartinson3@illinois.edu",
50+
"gender": "M"
51+
}
52+
53+
const student5 = {
54+
"id": 5,
55+
"name": "Antonietta",
56+
"email": "adaine5@samsung.com",
57+
"gender": "F",
58+
"multiplyNums": function(num1, num2) {
59+
return num1 * num2;
60+
}
61+
}
2262

2363
// ==== Challenge 2: Reading Object Data ====
2464
// Once your objects are created, log out the following requests from HR into the console:
2565

2666
// Mitzi's name
2767

68+
console.log(student1.name);
69+
2870
// Kennan's ID
2971

72+
console.log(student2.id);
73+
3074
// Keven's email
3175

76+
console.log(student3.email);
77+
3278
// Gannie's name
3379

80+
console.log(student4.name);
81+
3482
// Antonietta's Gender
3583

84+
console.log(student5.gender);
85+
3686
// ==== Challenge 3: Object Methods ====
3787
// Give Kennan the ability to say "Hello, my name is Kennan!" Use the console.log provided as a hint.
3888
// console.log(kennan.speak());
3989

90+
console.log(student2.speak());
91+
4092
// Antonietta loves math, give her the ability to multiply two numbers together and return the product. Use the console.log provided as a hint.
4193
//console.log(antonietta.multiplyNums(3,4));
4294

95+
console.log(student5.multiplyNums(3,4));
96+
4397
// === Great work! === Head over to the the arrays.js file or take a look at the stretch challenge
4498

4599
// ==== Stretch Challenge: Nested Objects and the this keyword ====
@@ -49,16 +103,48 @@ const example = {
49103
// 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
50104
// 4. Give each of the objects the ability to speak their names using the this keyword.
51105

52-
const parent = {}
106+
const parent = {
107+
name: "Susan",
108+
age: 70,
109+
speak: function() {
110+
return "My name is " + this.name + ".";
111+
},
112+
child: {
113+
name: "George",
114+
age: 50,
115+
speak: function() {
116+
return "My name is " + this.name + ".";
117+
},
118+
grandchild: {
119+
name: "Sam",
120+
age: 30,
121+
speak: function() {
122+
return "My name is " + this.name + ".";
123+
}
124+
}
125+
}
126+
}
53127

54128
// Log the parent object's name
55129

130+
console.log(parent.name);
131+
56132
// Log the child's age
57133

134+
console.log(parent.child.name);
135+
58136
// Log the name and age of the grandchild
59137

138+
console.log(parent.child.grandchild.name);
139+
60140
// Have the parent speak
61141

142+
console.log(parent.speak());
143+
62144
// Have the child speak
63145

146+
console.log(parent.child.speak());
147+
64148
// Have the grandchild speak
149+
150+
console.log(parent.child.grandchild.speak());

0 commit comments

Comments
 (0)