Skip to content

Commit fda67e2

Browse files
authored
Merge pull request #1 from ConConRob/Connor-Robertson
WEBEU1 Connor robertson
2 parents 87877e0 + 56c9c58 commit fda67e2

3 files changed

Lines changed: 103 additions & 31 deletions

File tree

‎assignments/arrays.js‎

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,54 @@ 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+
console.log(`Car 33 is a ${inventory[32].car_year} ${inventory[32].car_make} ${inventory[32].car_model}` );
6767

6868

6969

7070
// ==== Challenge 2 ====
7171
// 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.
72-
let lastCar = 0;
73-
console.log();
72+
let lastCar = inventory[inventory.length-1];
73+
console.log(`The last car is a ${lastCar.car_make} ${lastCar.car_model}`);
7474

7575
// ==== Challenge 3 ====
7676
// 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
77-
let carModels = [];
78-
console.log();
77+
const carModels = [];
78+
for(let i = 0; i< inventory.length-1; i++){
79+
let model = inventory[i].car_model;
80+
//make sure that every model is capitalized
81+
carModels.push(model.charAt(0).toUpperCase()+model.slice(1));
82+
}
83+
carModels.sort();
84+
console.log(carModels);
7985

8086
// ==== Challenge 4 ====
8187
// 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.
82-
let carYears = [];
83-
console.log();
88+
const carYears = [];
89+
for(let i = 0; i<inventory.length-1; i++){
90+
carYears.push(inventory[i].car_year);
91+
}
92+
console.log(carYears);
8493

8594
// ==== Challenge 5 ====
8695
// 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();
96+
const oldCars =[];
97+
for(let i = 0; i<carYears.length-1; i++){
98+
if(carYears[i]<2000){
99+
oldCars.push(carYears[i])
100+
}
101+
}
102+
console.log(oldCars.length);
89103

90104
// ==== Challenge 6 ====
91105
// 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();
106+
const BMWAndAudi =[];
107+
for(let i = 0; i<inventory.length; i++){
108+
const make = inventory[i].car_make;
109+
if(make==="BMW" || make==="Audi"){
110+
BMWAndAudi.push(inventory[i]);
111+
}
112+
}
113+
console.log(JSON.stringify(BMWAndAudi));
94114

95115

96116

‎assignments/objects.js‎

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,60 @@ const example = {
1818
}
1919

2020
// Write your intern objects here:
21-
22-
21+
const mitzi = {
22+
"id": 1,
23+
"name": "Mitzi",
24+
"email": "mmelloy0@psu.edu",
25+
"gender": "F",
26+
}
27+
const kennan = {
28+
"id": 2,
29+
"name": "Kennan",
30+
"email": "kdiben1@tinypic.com",
31+
"gender": "M",
32+
}
33+
const keven = {
34+
"id": 3,
35+
"name": "Mitzi",
36+
"email": "kmummery2@wikimedia.org",
37+
"gender": "M",
38+
}
39+
const gannie = {
40+
"id": 4,
41+
"name": "Gannie",
42+
"email": "gmartinson3@illinois.edu",
43+
"gender": "M",
44+
}
45+
const antonietta = {
46+
"id": 5,
47+
"name": "Antonietta",
48+
"email": "adaine5@samsung.com",
49+
"gender": "F",
50+
}
2351
// ==== Challenge 2: Reading Object Data ====
2452
// Once your objects are created, log out the following requests from HR into the console:
2553

2654
// Mitzi's name
27-
55+
console.log(mitzi.name);
2856
// Kennan's ID
29-
57+
console.log(kennan.id);
3058
// Keven's email
31-
59+
console.log(keven.email);
3260
// Gannie's name
33-
61+
console.log(gannie.name);
3462
// Antonietta's Gender
35-
63+
console.log(antonietta.gender);
3664
// ==== Challenge 3: Object Methods ====
3765
// Give Kennan the ability to say "Hello, my name is Kennan!" Use the console.log provided as a hint.
3866
// console.log(kennan.speak());
39-
67+
kennan.speak = function(){
68+
return `Hello, my name is ${this.name}`;
69+
}
70+
//console.log(kennan.speak());
4071
// Antonietta loves math, give her the ability to multiply two numbers together and return the product. Use the console.log provided as a hint.
4172
//console.log(antonietta.multiplyNums(3,4));
42-
73+
antonietta.multiplyNums = (x, y) => x*y;
74+
//console.log(antonietta.multiplyNums(3,4))
4375
// === Great work! === Head over to the the arrays.js file or take a look at the stretch challenge
4476

4577
// ==== Stretch Challenge: Nested Objects and the this keyword ====
@@ -49,16 +81,31 @@ const example = {
4981
// 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
5082
// 4. Give each of the objects the ability to speak their names using the this keyword.
5183

52-
const parent = {}
84+
const parent = {
85+
name: "Susan",
86+
age: 70,
87+
speak: function () {console.log(`My name is ${this.name}`);},
88+
child: {
89+
name: "George",
90+
age: 50,
91+
speak: function () {console.log(`My name is ${this.name}`);},
92+
grandchild: {
93+
name: "Sam",
94+
age: 30,
95+
speak: function () {console.log(`My name is ${this.name}`);},
96+
}
97+
}
98+
}
5399

54100
// Log the parent object's name
55-
101+
console.log(parent.name);
56102
// Log the child's age
57-
103+
console.log(parent.child.name);
58104
// Log the name and age of the grandchild
59-
105+
console.log(parent.child.grandchild.name);
60106
// Have the parent speak
61-
107+
parent.speak();
62108
// Have the child speak
63-
109+
parent.child.speak();
64110
// Have the grandchild speak
111+
parent.child.grandchild.speak();
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
// Take the commented ES5 syntax and convert it to ES6 arrow Syntax
22

33
// let myFunction = function () {};
4-
4+
const myFunction = () => {};
55
// let anotherFunction = function (param) {
66
// return param;
77
// };
8-
8+
const anotherFunction = param => param;
99
// let add = function (param1, param2) {
1010
// return param1 + param2;
1111
// };
1212
// add(1,2);
13-
13+
const add = (param1, param2) => param1+param2;
14+
console.log(add(1,2));
1415
// let subtract = function (param1, param2) {
1516
// return param1 - param2;
1617
// };
1718
// subtract(1,2);
18-
19+
const subtract = (param1, param2) => param1 - param2;
20+
console.log(subtract(1,2));
1921
// exampleArray = [1,2,3,4];
2022
// const triple = exampleArray.map(function (num) {
2123
// return num * 3;
2224
// });
23-
// console.log(triple);
25+
// console.log(triple);
26+
exampleArray = [1,2,3,4];
27+
const triple = exampleArray.map(num => num*3);
28+
console.log(triple);

0 commit comments

Comments
 (0)