Skip to content

Commit 4766370

Browse files
author
Ryan Boris
authored
Merge pull request #1 from brilles/brian-illes
added object
2 parents 87877e0 + fbafcb5 commit 4766370

3 files changed

Lines changed: 142 additions & 82 deletions

File tree

assignments/arrays.js

Lines changed: 76 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,58 @@
22

33
// The car dealer has all of their inventory housed in the array seen below. Scroll down past the data to find out how you can help the car dealer.
44

5-
let inventory = [{"id":1,"car_make":"Lincoln","car_model":"Navigator","car_year":2009},
6-
{"id":2,"car_make":"Mazda","car_model":"Miata MX-5","car_year":2001},
7-
{"id":3,"car_make":"Land Rover","car_model":"Defender Ice Edition","car_year":2010},
8-
{"id":4,"car_make":"Honda","car_model":"Accord","car_year":1983},
9-
{"id":5,"car_make":"Mitsubishi","car_model":"Galant","car_year":1990},
10-
{"id":6,"car_make":"Audi","car_model":"riolet","car_year":1995},
11-
{"id":7,"car_make":"Smart","car_model":"Fortwo","car_year":2009},
12-
{"id":8,"car_make":"Audi","car_model":"4000CS Quattro","car_year":1987},
13-
{"id":9,"car_make":"Ford","car_model":"Windstar","car_year":1996},
14-
{"id":10,"car_make":"Mercedes-Benz","car_model":"E-Class","car_year":2000},
15-
{"id":11,"car_make":"Infiniti","car_model":"G35","car_year":2004},
16-
{"id":12,"car_make":"Lotus","car_model":"Esprit","car_year":2004},
17-
{"id":13,"car_make":"Chevrolet","car_model":"Cavalier","car_year":1997},
18-
{"id":14,"car_make":"Dodge","car_model":"Ram Van 1500","car_year":1999},
19-
{"id":15,"car_make":"Dodge","car_model":"Intrepid","car_year":2000},
20-
{"id":16,"car_make":"Mitsubishi","car_model":"Montero Sport","car_year":2001},
21-
{"id":17,"car_make":"Buick","car_model":"Skylark","car_year":1987},
22-
{"id":18,"car_make":"Geo","car_model":"Prizm","car_year":1995},
23-
{"id":19,"car_make":"Oldsmobile","car_model":"Bravada","car_year":1994},
24-
{"id":20,"car_make":"Mazda","car_model":"Familia","car_year":1985},
25-
{"id":21,"car_make":"Chevrolet","car_model":"Express 1500","car_year":2003},
26-
{"id":22,"car_make":"Jeep","car_model":"Wrangler","car_year":1997},
27-
{"id":23,"car_make":"Eagle","car_model":"Talon","car_year":1992},
28-
{"id":24,"car_make":"Toyota","car_model":"MR2","car_year":2003},
29-
{"id":25,"car_make":"BMW","car_model":"525","car_year":2005},
30-
{"id":26,"car_make":"Cadillac","car_model":"Escalade","car_year":2005},
31-
{"id":27,"car_make":"Infiniti","car_model":"Q","car_year":2000},
32-
{"id":28,"car_make":"Suzuki","car_model":"Aerio","car_year":2005},
33-
{"id":29,"car_make":"Mercury","car_model":"Topaz","car_year":1993},
34-
{"id":30,"car_make":"BMW","car_model":"6 Series","car_year":2010},
35-
{"id":31,"car_make":"Pontiac","car_model":"GTO","car_year":1964},
36-
{"id":32,"car_make":"Dodge","car_model":"Ram Van 3500","car_year":1999},
37-
{"id":33,"car_make":"Jeep","car_model":"Wrangler","car_year":2011},
38-
{"id":34,"car_make":"Ford","car_model":"Escort","car_year":1991},
39-
{"id":35,"car_make":"Chrysler","car_model":"300M","car_year":2000},
40-
{"id":36,"car_make":"Volvo","car_model":"XC70","car_year":2003},
41-
{"id":37,"car_make":"Oldsmobile","car_model":"LSS","car_year":1997},
42-
{"id":38,"car_make":"Toyota","car_model":"Camry","car_year":1992},
43-
{"id":39,"car_make":"Ford","car_model":"Econoline E250","car_year":1998},
44-
{"id":40,"car_make":"Lotus","car_model":"Evora","car_year":2012},
45-
{"id":41,"car_make":"Ford","car_model":"Mustang","car_year":1965},
46-
{"id":42,"car_make":"GMC","car_model":"Yukon","car_year":1996},
47-
{"id":43,"car_make":"Mercedes-Benz","car_model":"R-Class","car_year":2009},
48-
{"id":44,"car_make":"Audi","car_model":"Q7","car_year":2012},
49-
{"id":45,"car_make":"Audi","car_model":"TT","car_year":2008},
50-
{"id":46,"car_make":"Oldsmobile","car_model":"Ciera","car_year":1995},
51-
{"id":47,"car_make":"Volkswagen","car_model":"Jetta","car_year":2007},
52-
{"id":48,"car_make":"Dodge","car_model":"Magnum","car_year":2008},
53-
{"id":49,"car_make":"Chrysler","car_model":"Sebring","car_year":1996},
54-
{"id":50,"car_make":"Lincoln","car_model":"Town Car","car_year":1999}];
55-
5+
let inventory = [
6+
{ id: 1, car_make: "Lincoln", car_model: "Navigator", car_year: 2009 },
7+
{ id: 2, car_make: "Mazda", car_model: "Miata MX-5", car_year: 2001 },
8+
{id: 3, car_make: "Land Rover", car_model: "Defender Ice Edition", car_year: 2010},
9+
{ id: 4, car_make: "Honda", car_model: "Accord", car_year: 1983 },
10+
{ id: 5, car_make: "Mitsubishi", car_model: "Galant", car_year: 1990 },
11+
{ id: 6, car_make: "Audi", car_model: "riolet", car_year: 1995 },
12+
{ id: 7, car_make: "Smart", car_model: "Fortwo", car_year: 2009 },
13+
{ id: 8, car_make: "Audi", car_model: "4000CS Quattro", car_year: 1987 },
14+
{ id: 9, car_make: "Ford", car_model: "Windstar", car_year: 1996 },
15+
{ id: 10, car_make: "Mercedes-Benz", car_model: "E-Class", car_year: 2000 },
16+
{ id: 11, car_make: "Infiniti", car_model: "G35", car_year: 2004 },
17+
{ id: 12, car_make: "Lotus", car_model: "Esprit", car_year: 2004 },
18+
{ id: 13, car_make: "Chevrolet", car_model: "Cavalier", car_year: 1997 },
19+
{ id: 14, car_make: "Dodge", car_model: "Ram Van 1500", car_year: 1999 },
20+
{ id: 15, car_make: "Dodge", car_model: "Intrepid", car_year: 2000 },
21+
{id: 16, car_make: "Mitsubishi", car_model: "Montero Sport", car_year: 2001},
22+
{ id: 17, car_make: "Buick", car_model: "Skylark", car_year: 1987 },
23+
{ id: 18, car_make: "Geo", car_model: "Prizm", car_year: 1995 },
24+
{ id: 19, car_make: "Oldsmobile", car_model: "Bravada", car_year: 1994 },
25+
{ id: 20, car_make: "Mazda", car_model: "Familia", car_year: 1985 },
26+
{ id: 21, car_make: "Chevrolet", car_model: "Express 1500", car_year: 2003 },
27+
{ id: 22, car_make: "Jeep", car_model: "Wrangler", car_year: 1997 },
28+
{ id: 23, car_make: "Eagle", car_model: "Talon", car_year: 1992 },
29+
{ id: 24, car_make: "Toyota", car_model: "MR2", car_year: 2003 },
30+
{ id: 25, car_make: "BMW", car_model: "525", car_year: 2005 },
31+
{ id: 26, car_make: "Cadillac", car_model: "Escalade", car_year: 2005 },
32+
{ id: 27, car_make: "Infiniti", car_model: "Q", car_year: 2000 },
33+
{ id: 28, car_make: "Suzuki", car_model: "Aerio", car_year: 2005 },
34+
{ id: 29, car_make: "Mercury", car_model: "Topaz", car_year: 1993 },
35+
{ id: 30, car_make: "BMW", car_model: "6 Series", car_year: 2010 },
36+
{ id: 31, car_make: "Pontiac", car_model: "GTO", car_year: 1964 },
37+
{ id: 32, car_make: "Dodge", car_model: "Ram Van 3500", car_year: 1999 },
38+
{ id: 33, car_make: "Jeep", car_model: "Wrangler", car_year: 2011 },
39+
{ id: 34, car_make: "Ford", car_model: "Escort", car_year: 1991 },
40+
{ id: 35, car_make: "Chrysler", car_model: "300M", car_year: 2000 },
41+
{ id: 36, car_make: "Volvo", car_model: "XC70", car_year: 2003 },
42+
{ id: 37, car_make: "Oldsmobile", car_model: "LSS", car_year: 1997 },
43+
{ id: 38, car_make: "Toyota", car_model: "Camry", car_year: 1992 },
44+
{ id: 39, car_make: "Ford", car_model: "Econoline E250", car_year: 1998 },
45+
{ id: 40, car_make: "Lotus", car_model: "Evora", car_year: 2012 },
46+
{ id: 41, car_make: "Ford", car_model: "Mustang", car_year: 1965 },
47+
{ id: 42, car_make: "GMC", car_model: "Yukon", car_year: 1996 },
48+
{ id: 43, car_make: "Mercedes-Benz", car_model: "R-Class", car_year: 2009 },
49+
{ id: 44, car_make: "Audi", car_model: "Q7", car_year: 2012 },
50+
{ id: 45, car_make: "Audi", car_model: "TT", car_year: 2008 },
51+
{ id: 46, car_make: "Oldsmobile", car_model: "Ciera", car_year: 1995 },
52+
{ id: 47, car_make: "Volkswagen", car_model: "Jetta", car_year: 2007 },
53+
{ id: 48, car_make: "Dodge", car_model: "Magnum", car_year: 2008 },
54+
{ id: 49, car_make: "Chrysler", car_model: "Sebring", car_year: 1996 },
55+
{ id: 50, car_make: "Lincoln", car_model: "Town Car", car_year: 1999 }
56+
];
5657

5758
// Example for loop:
5859

@@ -63,34 +64,44 @@ let inventory = [{"id":1,"car_make":"Lincoln","car_model":"Navigator","car_year"
6364

6465
// ==== Challenge 1 ====
6566
// 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*` );
67-
68-
69-
67+
console.log(`Car 33 is a ${inventory[32].car_year} ${inventory[32].car_make} ${inventory[32].car_model}.`);
7068
// ==== Challenge 2 ====
7169
// 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.
7270
let lastCar = 0;
73-
console.log();
71+
console.log(`${inventory[inventory.length-1].car_make} ${inventory[inventory.length-1].car_model}`);
7472

7573
// ==== Challenge 3 ====
7674
// 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
7775
let carModels = [];
78-
console.log();
76+
for (i in inventory) {
77+
carModels.push(inventory[i].car_make);
78+
}
79+
console.log(carModels.sort());
7980

8081
// ==== Challenge 4 ====
8182
// 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.
8283
let carYears = [];
83-
console.log();
84+
for (i in inventory) {
85+
carYears.push(inventory[i].car_year)
86+
}
87+
console.log(carYears);
8488

8589
// ==== Challenge 5 ====
8690
// 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.
87-
let oldCars =[];
88-
console.log();
91+
let oldCars = [];
92+
for (i in carYears) {
93+
if (carYears[i] < 2000) {
94+
oldCars.push(carYears[i]);
95+
}
96+
}
97+
console.log(oldCars.length);
8998

9099
// ==== Challenge 6 ====
91100
// 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.
92-
let BMWAndAudi =[];
93-
console.log();
94-
95-
96-
101+
let BMWAndAudi = [];
102+
for (i in inventory) {
103+
if (inventory[i].car_make === "BMW" || inventory[i].car_make === "Audi") {
104+
BMWAndAudi.push(inventory[i]);
105+
}
106+
}
107+
console.log(JSON.stringify(BMWAndAudi));

assignments/objects.js

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Let's get some practice writing a few objects for a new group of interns at a small business.
22

3-
// ==== Challenge 1: Writing Objects ====
3+
// ==== Challenge 1: Writing Objects ====
44
// HR needs some information on the new interns put into a database. Given an id, email, first name, and gender. Create an object for each person in the company list:
55

66
// 1,[email protected],Mitzi,F
@@ -11,45 +11,87 @@
1111

1212
// Example format of an intern object: 1,[email protected],Example,F
1313
const example = {
14-
"id": 0,
15-
"name": "Example",
16-
"email": "[email protected]",
17-
"gender": "F"
18-
}
14+
id: 0,
15+
name: "Example",
16+
17+
gender: "F"
18+
};
1919

2020
// Write your intern objects here:
21-
22-
23-
// ==== Challenge 2: Reading Object Data ====
21+
const mitzi = {
22+
id: 1,
23+
name: "Mitzi",
24+
25+
gender: "F"
26+
};
27+
28+
const kennan = {
29+
id: 2,
30+
name: "Kennan",
31+
32+
gender: "M"
33+
};
34+
35+
const keven = {
36+
id: 3,
37+
name: "Keven",
38+
39+
gender: "M"
40+
};
41+
42+
const gannie = {
43+
id: 4,
44+
name: "Gannie",
45+
46+
gender: "M"
47+
};
48+
49+
const antonietta = {
50+
id: 5,
51+
name: "Antonietta",
52+
53+
gender: "F"
54+
};
55+
56+
// ==== Challenge 2: Reading Object Data ====
2457
// Once your objects are created, log out the following requests from HR into the console:
2558

2659
// Mitzi's name
27-
60+
console.log(mitzi.name);
2861
// Kennan's ID
29-
62+
console.log(kennan.id);
3063
// Keven's email
31-
64+
console.log(keven.email);
3265
// Gannie's name
33-
66+
console.log(gannie.name);
3467
// Antonietta's Gender
68+
console.log(antonietta.gender);
3569

36-
// ==== Challenge 3: Object Methods ====
70+
// ==== Challenge 3: Object Methods ====
3771
// Give Kennan the ability to say "Hello, my name is Kennan!" Use the console.log provided as a hint.
3872
// console.log(kennan.speak());
73+
kennan.speak = function() {
74+
return `Hello, my name is ${this.name}!`;
75+
};
76+
console.log(kennan.speak());
3977

4078
// Antonietta loves math, give her the ability to multiply two numbers together and return the product. Use the console.log provided as a hint.
4179
//console.log(antonietta.multiplyNums(3,4));
80+
antonietta.multiplyNums = function(num1, num2) {
81+
return num1 * num2;
82+
};
83+
console.log(antonietta.multiplyNums(3, 4));
4284

4385
// === Great work! === Head over to the the arrays.js file or take a look at the stretch challenge
4486

45-
// ==== Stretch Challenge: Nested Objects and the this keyword ====
87+
// ==== Stretch Challenge: Nested Objects and the this keyword ====
4688

4789
// 1. Create a parent object with properties for name and age. Make the name Susan and the age 70.
4890
// 2. Nest a child object in the parent object with name and age as well. The name will be George and the age will be 50.
4991
// 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
5092
// 4. Give each of the objects the ability to speak their names using the this keyword.
5193

52-
const parent = {}
94+
const parent = {};
5395

5496
// Log the parent object's name
5597

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

33
// let myFunction = function () {};
4+
let myFunction = () => {};
45

56
// let anotherFunction = function (param) {
67
// return param;
78
// };
9+
let anotherFunction = (param) => param;
810

911
// let add = function (param1, param2) {
1012
// return param1 + param2;
1113
// };
1214
// add(1,2);
15+
let add = (param1, param2) => param1 + param2;
1316

1417
// let subtract = function (param1, param2) {
1518
// return param1 - param2;
1619
// };
1720
// subtract(1,2);
21+
let subtract = (param1, param2) => param1 - param2;
1822

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

0 commit comments

Comments
 (0)