Skip to content

Commit 457dcc4

Browse files
committed
adding files
1 parent 86fe720 commit 457dcc4

2 files changed

Lines changed: 79 additions & 17 deletions

File tree

‎assignments/arrays.js‎

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,32 +63,64 @@ 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(inventory[32]);
6767

6868
// ==== Challenge 2 ====
6969
// 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.
7070
let lastCar = 0;
71-
console.log();
71+
console.log(inventory.slice(-1)[0]);
7272

7373
// ==== Challenge 3 ====
7474
// 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
75-
let carModels = [];
76-
console.log();
75+
function compareValues(key, order='asc') {
76+
return function(a, b) {
77+
if(!a.hasOwnProperty(key) ||
78+
!b.hasOwnProperty(key)) {
79+
return 0;
80+
}
81+
82+
const varA = (typeof a[key] === 'string') ?
83+
a[key].toUpperCase() : a[key];
84+
const varB = (typeof b[key] === 'string') ?
85+
b[key].toUpperCase() : b[key];
86+
87+
let comparison = 0;
88+
if (varA > varB) {
89+
comparison = 1;
90+
} else if (varA < varB) {
91+
comparison = -1;
92+
}
93+
return (
94+
(order == 'desc') ?
95+
(comparison * -1) : comparison
96+
);
97+
};
98+
}
99+
console.log( inventory.sort(compareValues('car_make', 'asc')));
77100

78101
// ==== Challenge 4 ====
79102
// 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.
103+
let result = inventory.map(a => a.car_year);
80104
let carYears = [];
81-
console.log();
105+
result.sort()
106+
console.log(result);
82107

83108
// ==== Challenge 5 ====
84109
// 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.
85110
let oldCars = [];
86-
console.log();
111+
112+
oldCars = result.slice(25, 100)
113+
console.log(oldCars);
87114

88115
// ==== Challenge 6 ====
89116
// 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.
90117
let BMWAndAudi = [];
91-
console.log();
118+
for (let i =0; i<inventory.length;i++ ){
119+
if (inventory[i].car_make == "BMW" || inventory[i].car_make == "Audi"){
120+
BMWAndAudi.push(inventory[i])
121+
}
122+
}
123+
console.log(BMWAndAudi);
92124

93125

94126

‎assignments/objects.js‎

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
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,mmelloy0@psu.edu,Mitzi,F
7-
// 2,kdiben1@tinypic.com,Kennan,M
8-
// 3,kmummery2@wikimedia.org,Keven,M
7+
// 2,kdiben1@tinypic.com,,M
8+
// 3,kmummery2@wikimedia.org,,M
99
// 4,gmartinson3@illinois.edu,Gannie,M
1010
// 5,adaine5@samsung.com,Antonietta,F
1111

@@ -18,28 +18,58 @@ const example = {
1818
}
1919

2020
// Write your intern objects here:
21-
21+
const intern1 = {
22+
"id": 0,
23+
"name": "Mitzi",
24+
"email": "mmelloy0@psu.edu",
25+
"gender": "F"
26+
}
27+
const intern2 = {
28+
"id": 1,
29+
"name": "Kennan",
30+
"email": "kdiben1@tinypic.com",
31+
"gender": "M"
32+
}
33+
const intern3 = {
34+
"id": 2,
35+
"name": "Keven",
36+
"email": "kmummery2@wikimedia.org",
37+
"gender": "M"
38+
}
39+
const intern4 = {
40+
"id": 3,
41+
"name": "Gannie",
42+
"email": "gmartinson3@illinois.edu",
43+
"gender": "M"
44+
}
45+
const intern5 = {
46+
"id": 4,
47+
"name": "Antonietta",
48+
"email": "adaine5@samsung.com",
49+
"gender": "M"
50+
}
2251

2352
// ==== Challenge 2: Reading Object Data ====
2453
// Once your objects are created, log out the following requests from HR into the console:
2554

2655
// Mitzi's name
27-
56+
console.log(intern1.name)
2857
// Kennan's ID
29-
58+
console.log(intern2.id)
3059
// Keven's email
31-
60+
console.log(intern3.email)
3261
// Gannie's name
33-
62+
console.log(intern4.name)
3463
// Antonietta's Gender
35-
64+
console.log(intern5.gender)
3665
// ==== Challenge 3: Object Methods ====
3766
// Give Kennan the ability to say "Hello, my name is Kennan!" Use the console.log provided as a hint.
38-
// console.log(kennan.speak());
67+
68+
console.log("hello my name is ", intern2.name);
3969

4070
// Antonietta loves math, give her the ability to multiply two numbers together and return the product. Use the console.log provided as a hint.
4171
//console.log(antonietta.multiplyNums(3,4));
42-
72+
console.log("hello i can add and my name is", intern4.name, 3 * 4)
4373
// === Great work! === Head over to the the arrays.js file or take a look at the stretch challenge
4474

4575
// ==== Stretch Challenge: Nested Objects and the this keyword ====

0 commit comments

Comments
 (0)