You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 72d7f13
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: assignments/arrays.js
+36-8Lines changed: 36 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -75,30 +75,58 @@ let inventory = [
75
75
76
76
// ==== Challenge 1 ====
77
77
// 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:
78
-
console.log(`Car 33 is a *car year goes here* *car make goes here* *car model goes here*`);
78
+
console.log('Car 33 is a '+inventory[32].car_year+' '+inventory[32].car_make+' '+inventory[32].car_model+'.');
79
79
80
80
// ==== Challenge 2 ====
81
81
// 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.
82
82
letlastCar=0;
83
-
console.log();
83
+
84
+
for(leti=0;i<inventory.length;i++){
85
+
if(inventory[i]===inventory[inventory.length-1]){
86
+
console.log(inventory[i]);
87
+
}
88
+
}
84
89
85
90
// ==== Challenge 3 ====
86
91
// 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
87
92
letcarModels=[];
88
-
letcarModelsSorted=[];
89
-
console.log();
93
+
94
+
for(leti=0;i<inventory.length;i++){
95
+
letmodels=inventory[i].car_model;
96
+
carModels.push(models);
97
+
carModels.sort();
98
+
console.log(carModels);
99
+
}
90
100
91
101
// ==== Challenge 4 ====
92
102
// 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.
93
103
letcarYears=[];
94
-
console.log();
104
+
105
+
for(leti=0;i<inventory.length;i++){
106
+
constyear=inventory[i].car_year;
107
+
carYears.push(year);
108
+
console.log(carYears);
109
+
}
95
110
96
111
// ==== Challenge 5 ====
97
112
// 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.
98
113
letoldCars=[];
99
-
console.log();
114
+
115
+
for(leti=0;i<inventory.length;i++){
116
+
constyear=inventory[i].car_year;
117
+
if(year<2000){
118
+
oldCars.push(year);
119
+
console.log(oldCars);
120
+
}
121
+
}
100
122
101
123
// ==== Challenge 6 ====
102
124
// 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.
Copy file name to clipboardExpand all lines: assignments/objects.js
+47-2Lines changed: 47 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,46 @@ const example = {
18
18
}
19
19
20
20
// Write your intern objects here:
21
+
constMitzi={
22
+
id: 1,
23
+
name: "Mitzi",
24
+
email: "mmelloy0@psu.edu",
25
+
gender: "F",
26
+
}
27
+
28
+
constKennan={
29
+
id: 2,
30
+
name: "Kennan",
31
+
email: "kdiben1@tinypic.com",
32
+
gender: "M",
33
+
speak : function(){
34
+
return"Hello, my name is "+this.name;
35
+
}
36
+
}
21
37
38
+
constKeven={
39
+
id: 3,
40
+
name: "Keven",
41
+
email: "kmummery2@wikimedia.org",
42
+
gender: "M",
43
+
}
44
+
45
+
constGannie={
46
+
id: 4,
47
+
name: "Gannie",
48
+
email: "mmelloy0@psu.edu",
49
+
gender: "M",
50
+
}
51
+
52
+
constAntonietta={
53
+
id: 5,
54
+
name: "Antonietta",
55
+
email: "mmelloy0@psu.edu",
56
+
gender: "F",
57
+
multiplyNums : function(num1,num2){
58
+
returnnum1*num2;
59
+
}
60
+
}
22
61
23
62
// ==== Challenge 2: Reading Object Data ====
24
63
// Once your objects are created, log out the following requests from HR into the console:
@@ -33,12 +72,18 @@ const example = {
33
72
34
73
// Antonietta's Gender
35
74
75
+
console.log(Mitzi.name);
76
+
console.log(Kennan.id);
77
+
console.log(Keven.email);
78
+
console.log(Gannie.name);
79
+
console.log(Antonietta.gender);
80
+
36
81
// ==== Challenge 3: Object Methods ====
37
82
// Give Kennan the ability to say "Hello, my name is Kennan!" Use the console.log provided as a hint.
38
-
// console.log(kennan.speak());
83
+
console.log(Kennan.speak());
39
84
40
85
// 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
+
console.log(Antonietta.multiplyNums(3,4));
42
87
43
88
// === Great work! === Head over to the the arrays.js. You may come back and attempt the Stretch Challenge once you have completed the challenges in arrays.js and function-conversion.js.
0 commit comments