|
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 ==== |
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: |
| 3 | +// ==== Challenge 1: Writing Objects ==== |
| 4 | +// HR needs some information on the new interns put into a database. |
| 5 | +// Given an id, email, first name, and gender. |
| 6 | +// Create an object for each person in the company list: |
5 | 7 |
|
6 | 8 | |
7 | 9 | |
|
11 | 13 |
|
12 | 14 | // Example format of an intern object: 1,[email protected],Example,F |
13 | 15 | const example = { |
14 | | - "id": 0, |
15 | | - "name": "Example", |
16 | | - |
17 | | - "gender": "F" |
18 | | -} |
| 16 | + id: 0, |
| 17 | + name: "Example", |
| 18 | + |
| 19 | + gender: "F" |
| 20 | +}; |
19 | 21 |
|
20 | 22 | // Write your intern objects here: |
21 | 23 |
|
22 | | - |
23 | | -// ==== Challenge 2: Reading Object Data ==== |
| 24 | +const intern1 = { |
| 25 | + id: 1, |
| 26 | + name: "Mitzi", |
| 27 | + |
| 28 | + gender: "F" |
| 29 | +}; |
| 30 | + |
| 31 | +const intern2 = { |
| 32 | + id: 2, |
| 33 | + name: "Kennan", |
| 34 | + |
| 35 | + gender: "M", |
| 36 | + speak: function() { |
| 37 | + console.log("Hello, my name is Kennan!"); |
| 38 | + } |
| 39 | +}; |
| 40 | + |
| 41 | +const intern3 = { |
| 42 | + id: 3, |
| 43 | + name: "Keven", |
| 44 | + |
| 45 | + gender: "M" |
| 46 | +}; |
| 47 | + |
| 48 | +const intern4 = { |
| 49 | + id: 4, |
| 50 | + name: "Gannie", |
| 51 | + |
| 52 | + gender: "M" |
| 53 | +}; |
| 54 | + |
| 55 | +const intern5 = { |
| 56 | + id: 5, |
| 57 | + name: "Antonietta", |
| 58 | + |
| 59 | + gender: "F", |
| 60 | + theMaths: function(num1, num2) { |
| 61 | + console.log(num1 * num2); |
| 62 | + } |
| 63 | +}; |
| 64 | + |
| 65 | +// ==== Challenge 2: Reading Object Data ==== |
24 | 66 | // Once your objects are created, log out the following requests from HR into the console: |
25 | 67 |
|
26 | 68 | // Mitzi's name |
| 69 | +console.log(intern1.name); |
27 | 70 |
|
28 | 71 | // Kennan's ID |
| 72 | +console.log(intern2.name); |
29 | 73 |
|
30 | 74 | // Keven's email |
| 75 | +console.log(intern3.email); |
31 | 76 |
|
32 | 77 | // Gannie's name |
| 78 | +console.log(intern4.name); |
33 | 79 |
|
34 | 80 | // Antonietta's Gender |
| 81 | +console.log(intern5.gender); |
35 | 82 |
|
36 | | -// ==== Challenge 3: Object Methods ==== |
| 83 | +// ==== Challenge 3: Object Methods ==== |
37 | 84 | // Give Kennan the ability to say "Hello, my name is Kennan!" Use the console.log provided as a hint. |
| 85 | + |
| 86 | +intern2.speak(); |
| 87 | + |
38 | 88 | // console.log(kennan.speak()); |
39 | 89 |
|
40 | | -// Antonietta loves math, give her the ability to multiply two numbers together and return the product. Use the console.log provided as a hint. |
| 90 | +// Antonietta loves math, give her the ability to multiply two numbers together and return the product. |
| 91 | +// Use the console.log provided as a hint. |
41 | 92 | //console.log(antonietta.multiplyNums(3,4)); |
42 | 93 |
|
| 94 | +intern5.theMaths(2, 5); |
| 95 | + |
43 | 96 | // === Great work! === Head over to the the arrays.js file or take a look at the stretch challenge |
44 | 97 |
|
45 | | -// ==== Stretch Challenge: Nested Objects and the this keyword ==== |
| 98 | +// ==== Stretch Challenge: Nested Objects and the this keyword ==== |
46 | 99 |
|
47 | 100 | // 1. Create a parent object with properties for name and age. Make the name Susan and the age 70. |
48 | | -// 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 | | -// 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 |
| 101 | +// 2. Nest a child object in the parent object with name and age as well. |
| 102 | +// The name will be George and the age will be 50. |
| 103 | +// 3. Nest a grandchild object in the child object with properties for name and age. |
| 104 | +// The name will be Sam and the age will be 30 |
50 | 105 | // 4. Give each of the objects the ability to speak their names using the this keyword. |
51 | 106 |
|
52 | | -const parent = {} |
| 107 | +const parent = {}; |
53 | 108 |
|
54 | 109 | // Log the parent object's name |
55 | 110 |
|
|
0 commit comments