|
1 | 1 | // Let's get some practice writing a few objects for a new group of interns at a small business. |
2 | 2 |
|
3 | | -// ==== Challenge 1: Writing Objects ==== |
| 3 | +// ==== Challenge 1: Writing Objects ==== |
4 | 4 | // 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: |
5 | 5 |
|
6 | 6 | // 1,mmelloy0@psu.edu,Mitzi,F |
|
11 | 11 |
|
12 | 12 | // Example format of an intern object: 1,examples@you.edu,Example,F |
13 | 13 | const example = { |
14 | | - "id": 0, |
15 | | - "name": "Example", |
16 | | - "email": "examples@you.edu", |
17 | | - "gender": "F" |
18 | | -} |
| 14 | + id: 0, |
| 15 | + name: "Example", |
| 16 | + email: "examples@you.edu", |
| 17 | + gender: "F" |
| 18 | +}; |
19 | 19 |
|
20 | 20 | // Write your intern objects here: |
| 21 | +const intern = { |
| 22 | + Mitzi: { |
| 23 | + id: 1, |
| 24 | + name: "Mitzi", |
| 25 | + email: "mmelloy0@psu.edu", |
| 26 | + gender: "F" |
| 27 | + }, |
| 28 | + Kennan: { |
| 29 | + id: 2, |
| 30 | + name: "Kennan", |
| 31 | + email: "kdiben1@tinypic.com", |
| 32 | + gender: "M" |
| 33 | + }, |
| 34 | + Keven: { |
| 35 | + id: 3, |
| 36 | + name: "Keven", |
| 37 | + email: "kmummery2@wikimedia.org", |
| 38 | + gender: "M" |
| 39 | + }, |
| 40 | + |
| 41 | + Gannie: { |
| 42 | + id: 4, |
| 43 | + name: "Gannie", |
| 44 | + email: "gmartinson3@illinois.edu", |
| 45 | + gender: "M" |
| 46 | + }, |
| 47 | + Antonietta: { |
| 48 | + id: 5, |
| 49 | + name: "Antonietta", |
| 50 | + email: "adaine5@samsung.com", |
| 51 | + gender: "F" |
| 52 | + } |
| 53 | +}; |
| 54 | +// 1, mmelloy0@psu.edu, Mitzi, F |
| 55 | +// 2,kdiben1@tinypic.com,Kennan,M |
| 56 | +// 3,kmummery2@wikimedia.org,Keven,M |
| 57 | +// 4,gmartinson3@illinois.edu,Gannie,M |
| 58 | +// 5,adaine5@samsung.com,Antonietta,F |
21 | 59 |
|
22 | | - |
23 | | -// ==== Challenge 2: Reading Object Data ==== |
| 60 | +// ==== Challenge 2: Reading Object Data ==== |
24 | 61 | // Once your objects are created, log out the following requests from HR into the console: |
25 | | - |
| 62 | +console.log("Student Info Request:"); |
| 63 | +console.log("Mitzi's name is " + intern.Mitzi.name); |
26 | 64 | // Mitzi's name |
27 | | - |
| 65 | +console.log("Kennan's ID is " + intern.Kennan.id); |
28 | 66 | // Kennan's ID |
29 | | - |
| 67 | +console.log("Keven's email is " + intern.Keven.email); |
30 | 68 | // Keven's email |
31 | | - |
| 69 | +console.log("Gannie's name is " + intern.Gannie.name); |
32 | 70 | // Gannie's name |
33 | | - |
| 71 | +console.log("Antonietta's gender is " + intern.Antonietta.gender); |
34 | 72 | // Antonietta's Gender |
35 | 73 |
|
36 | | -// ==== Challenge 3: Object Methods ==== |
| 74 | +// ==== Challenge 3: Object Methods ==== |
37 | 75 | // Give Kennan the ability to say "Hello, my name is Kennan!" Use the console.log provided as a hint. |
38 | 76 | // console.log(kennan.speak()); |
39 | | - |
| 77 | +intern.Kennan.speak = function() { |
| 78 | + var hello = "Hello, my name is Kennan!"; |
| 79 | + return hello; |
| 80 | +}; |
| 81 | +console.log(intern.Kennan.speak()); |
40 | 82 | // 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 | 83 | //console.log(antonietta.multiplyNums(3,4)); |
42 | 84 |
|
43 | 85 | // === Great work! === Head over to the the arrays.js file or take a look at the stretch challenge |
44 | 86 |
|
45 | | -// ==== Stretch Challenge: Nested Objects and the this keyword ==== |
| 87 | +// ==== Stretch Challenge: Nested Objects and the this keyword ==== |
46 | 88 |
|
47 | 89 | // 1. Create a parent object with properties for name and age. Make the name Susan and the age 70. |
48 | 90 | // 2. Nest a child object in the parent object with name and age as well. The name will be George and the age will be 50. |
49 | 91 | // 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 |
50 | 92 | // 4. Give each of the objects the ability to speak their names using the this keyword. |
51 | 93 |
|
52 | | -const parent = {} |
| 94 | +const parent = {}; |
53 | 95 |
|
54 | 96 | // Log the parent object's name |
55 | 97 |
|
|
0 commit comments