Skip to content

Commit 1198c65

Browse files
committed
Finished both objects and arrays challenges.
1 parent 1abe623 commit 1198c65

2 files changed

Lines changed: 67 additions & 9 deletions

File tree

assignments/arrays.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,48 @@ 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*` );
67-
68-
66+
console.log(`Car 33 is a ${inventory[32]["car_year"]} ${inventory[32]["car_make"]} ${inventory[32]["car_model"]}`);
6967

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.
72-
let lastCar = 0;
73-
console.log();
70+
let lastCar = inventory[(inventory.length) - 1];
71+
console.log(`${lastCar["car_make"]} ${lastCar["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(let i = 0; i < inventory.length; i++) {
77+
carModels.push(inventory[i]["car_model"]);
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(let i = 0; i < inventory.length; i++) {
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.
8791
let oldCars =[];
88-
console.log();
92+
for(let i = 0; i < carYears.length; i++) {
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.
92101
let BMWAndAudi =[];
93-
console.log();
102+
for(let i = 0; i < inventory.length; i++) {
103+
if ((inventory[i]["car_make"]) === ("BMW" || "Audi")) {
104+
BMWAndAudi.push(inventory[i]);
105+
}
106+
}
107+
console.log(JSON.stringify(BMWAndAudi));
94108

95109

96110

assignments/objects.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,71 @@ const example = {
1818
}
1919

2020
// Write your intern objects here:
21+
const mitzi = {
22+
'id': 1,
23+
'name': 'Mitzi',
24+
'email': '[email protected]',
25+
'gender': 'F'
26+
}
27+
const kennan = {
28+
'id': 2,
29+
'name': 'Kennan',
30+
'email': '[email protected]',
31+
'gender': 'M'
32+
}
33+
const keven = {
34+
'id': 3,
35+
'name': 'Keven',
36+
'email': '[email protected]',
37+
'gender': 'M'
38+
}
39+
const gannie = {
40+
'id': 4,
41+
'name': 'Gannie',
42+
'email': '[email protected]',
43+
'gender': 'M'
44+
}
45+
const antonietta = {
46+
'id': 5,
47+
'name': 'Antonietta',
48+
'email': '[email protected]',
49+
'gender': 'F'
50+
}
2151

2252

2353
// ==== Challenge 2: Reading Object Data ====
2454
// Once your objects are created, log out the following requests from HR into the console:
2555

2656
// Mitzi's name
57+
console.log(mitzi["name"]);
2758

2859
// Kennan's ID
60+
console.log(kennan["id"]);
2961

3062
// Keven's email
63+
console.log(keven["email"]);
3164

3265
// Gannie's name
66+
console.log(gannie["name"]);
3367

3468
// Antonietta's Gender
69+
console.log(antonietta["gender"]);
70+
3571

3672
// ==== Challenge 3: Object Methods ====
3773
// Give Kennan the ability to say "Hello, my name is Kennan!" Use the console.log provided as a hint.
3874
// console.log(kennan.speak());
75+
kennan["speak"] = function() {
76+
return ("Hello, my name is Kennan!");
77+
}
78+
console.log(kennan.speak());
3979

4080
// Antonietta loves math, give her the ability to multiply two numbers together and return the product. Use the console.log provided as a hint.
4181
//console.log(antonietta.multiplyNums(3,4));
82+
antonietta["multiplyNums"] = function (a, b) {
83+
return a * b;
84+
}
85+
console.log(antonietta.multiplyNums(3,4));
4286

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

0 commit comments

Comments
 (0)