forked from bloominstituteoftechnology/JavaScript-I
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects.js
More file actions
81 lines (62 loc) · 2.74 KB
/
objects.js
File metadata and controls
81 lines (62 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Let's get some practice writing a few objects for a new group of interns at a small business.
// ==== Challenge 1: Writing Objects ====
// 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:
// Example format of an intern object: 1,[email protected],Example,F
const example = {
"id": 0,
"name": "Example",
"gender": "F"
}
// { id: 0, name: 'Example', email: 'examples@you.edu', gender: 'F' }
function Intern(id,email,name,gender) {
this.id = id;
this.email = email;
this.name = name;
this.gender = gender;
}
// ==== Challenge 2: Reading Object Data ====
// Once your objects are created, log out the following requests from HR into the console:
// Mitzi's name
console.log(Mitzi.name);
// Kennan's ID
console.log(Keven.id);
// Keven's email
console.log(Keven.email);
// Gannie's name
console.log(Gannie.name);
// Antonietta's Gender
console.log(Antonietta.gender);
// ==== Challenge 3: Object Methods ====
// Give Kennan the ability to say "Hello, my name is Kennan!" Use the console.log provided as a hint.
// console.log(kennan.speak());
Intern.prototype.say_name = function() {
let speak = "Hello, my name is "
return speak + this.name
};
console.log(Kennan.say_name());
// Antonietta loves math, give her the ability to multiply two numbers together and return the product. Use the console.log provided as a hint.
//console.log(antonietta.multiplyNums(3,4));
Intern.prototype.multiplyNums = function(a,b) {
let product = a * b;
return product;
};
console.log(Antonietta.multiplyNums(3,4));
// === Great work! === Head over to the the arrays.js file or take a look at the stretch challenge
// ==== Stretch Challenge: Nested Objects and the this keyword ====
// 1. Create a parent object with properties for name and age. Make the name Susan and the age 70.
// 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.
// 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
// 4. Give each of the objects the ability to speak their names using the this keyword.
const parent = {}
// Log the parent object's name
// Log the child's age
// Log the name and age of the grandchild
// Have the parent speak
// Have the child speak
// Have the grandchild speak