Skip to content

Commit a5e9c95

Browse files
Barbara HunterBarbara Hunter
authored andcommitted
updated arrays.js updated objects.js
1 parent 5ee838a commit a5e9c95

2 files changed

Lines changed: 74 additions & 13 deletions

File tree

assignments/arrays.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,41 +64,53 @@ let inventory = [{"id":1,"car_make":"Lincoln","car_model":"Navigator","car_year"
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:
6666
//
67-
for (let i = 0; i < 50; i++) {
67+
for (let i = 0; i < inventory.length; i++) {
6868
if (inventory[i].id === 33) {
69-
console.log (inventory[i]);
69+
console.log(`Car 33 is a ${inventory[i].car_year} ${inventory[i].car_make} ${inventory[i].car_model}` );
7070
}
7171
}
7272

7373

7474

7575
// ==== Challenge 2 ====
7676
// 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.
77-
for (let lastCar = 0; lastCar < inventory.length; lastCar++){
78-
if (inventory[lastCar].id === inventory.length) {
79-
console.log (inventory[lastCar]);
80-
}
81-
}
77+
78+
let lastCar = (inventory[inventory.length -1]);
79+
console.log (`${lastCar.car_make} ${lastCar.car_model}`);
8280

8381

8482
// ==== Challenge 3 ====
8583
// 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
8684
let carModels = [];
87-
console.log();
85+
for (let i = 0; i < inventory.length; i++){
86+
carModels[i]= inventory[i].car_model;
87+
}
88+
console.log(carModels.sort());
8889

8990
// ==== Challenge 4 ====
9091
// 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.
9192
let carYears = [];
92-
console.log();
93+
for (let i = 0; i < inventory.length; i++){
94+
carYears[i]= inventory[i].car_year;
95+
}
96+
console.log(carYears.sort());
9397

9498
// ==== Challenge 5 ====
9599
// 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.
96100
let oldCars =[];
97-
console.log();
101+
for (let i = 0; i < inventory.length; i++){
102+
if (carYears[i]<2000){
103+
oldCars.push(carYears[i]);
104+
}
105+
}
106+
console.log(oldCars.length);
98107

99108
// ==== Challenge 6 ====
100109
// 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.
101110
let BMWAndAudi =[];
111+
for (let i = 0; i < inventory.length; i++){
112+
if (inventory[i].car_make === "Audi" || inventory[i].car_make === "BMW" )
113+
}
102114
console.log();
103115

104116

assignments/objects.js

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,84 @@
1010
// 5,[email protected],Antonietta,F
1111

1212
// Example format of an intern object: 1,[email protected],Example,F
13+
// Write your intern objects here:
1314
const example = {
1415
"id": 0,
1516
"name": "Example",
1617
"email": "[email protected]",
1718
"gender": "F"
1819
}
20+
const Mitzi = {
21+
"id": 1,
22+
"name": "Mitzi",
23+
"email": "[email protected]",
24+
"gender": "F"
25+
}
26+
const Kennan = {
27+
"id": 2,
28+
"name": "Kennan",
29+
"email": "[email protected]",
30+
"gender": "M"
31+
}
32+
const Keven = {
33+
"id": 3,
34+
"name": "Keven",
35+
"email": "[email protected]",
36+
"gender": "M"
37+
}
38+
const Gannie = {
39+
"id": 4,
40+
"name": "Gannie",
41+
"email": "[email protected]",
42+
"gender": "M"
43+
}
44+
const Antonietta = {
45+
"id": 5,
46+
"name": "Antonietta",
47+
"email": "[email protected]",
48+
"gender": "F"
49+
}
50+
1951

20-
// Write your intern objects here:
2152

2253

2354
// ==== Challenge 2: Reading Object Data ====
2455
// Once your objects are created, log out the following requests from HR into the console:
2556

2657
// Mitzi's name
2758

59+
console.log (Mitzi.name);
60+
2861
// Kennan's ID
2962

63+
console.log (Kennan.id);
64+
3065
// Keven's email
3166

67+
console.log (Keven.email);
68+
3269
// Gannie's name
3370

71+
console.log (Gannie.name);
72+
3473
// Antonietta's Gender
3574

75+
console.log (Antonietta.gender);
76+
3677
// ==== Challenge 3: Object Methods ====
3778
// Give Kennan the ability to say "Hello, my name is Kennan!" Use the console.log provided as a hint.
38-
// console.log(kennan.speak());
79+
Kennan.speak = function (){
80+
console.log ("Hello my name is Kennan!!!!");
81+
}
82+
83+
console.log(kennan.speak());
3984

4085
// Antonietta loves math, give her the ability to multiply two numbers together and return the product. Use the console.log provided as a hint.
41-
//console.log(antonietta.multiplyNums(3,4));
86+
Antonietta.multiplyNums = function(x,y){
87+
return x*y;
88+
}
89+
90+
console.log(Antonietta.multiplyNums(3,4));
4291

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

0 commit comments

Comments
 (0)