forked from turingschool/m0_fe_objects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects.js
More file actions
103 lines (73 loc) · 2.79 KB
/
objects.js
File metadata and controls
103 lines (73 loc) · 2.79 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Activity:
// In the below exercises, write code that achieves
// the desired result. To check your work, run this
// file in your Terminal.
var foods = {
apples: 23,
grapes: 507,
eggs: 48
}
// Write code that prints all of the 'keys' of the foods variable
// you created above:
var keys = Object.keys(foods);
console.log(keys);
// Write code that prints all of the 'values' of the foods variable
// you created above:
var values = Object.values(foods);
console.log(values);
// Write code that prints the value of the second food of the foods variable
// you created above:
console.log(foods.grapes)
// Write code that adds a food to the foods object.
// Then, print the updated object:
foods.popTarts = 2
foods.sourPatchKids = 4
// -------------------
// Part 2: Email
// -------------------
// Think about all the pieces of information associated with one single email in your inbox.
// It has a sender, a subject, ...
// Declare a variable that stores an object. Each key should be an attribute of an email and each
// value should be some appropriate value for that key. Work to have at least 5 key-value pairs.
// Write code that logs your email object to the terminal.
// Write code that logs all of the 'keys' of the email object
// you created above:
// YOUR CODE HERE
// Write code that logs all of the 'values' of the email object
// you created above:
// YOUR CODE HERE
// -------------------
// Part 3: Many Emails - CHALLENGE!
// -------------------
// LONG EXAMPLE:
// Now that we've learned about Objects AND Arrays, we can combine them.
// Check out the following example of an array of Instagram posts:
var posts = ["image at beach", "holiday party", "adorable puppy", "video of cute baby"];
// An Array of Objects is probably more realistic. Objects are a data type that's great
// for storing more complex data. Below, we can store multiple key-value pairs
// that relate to each individual Instagram post:
posts = [
{
imageSrc: "./images/beach.png",
caption: "At the beach with my besties",
timestamp: "4:37 PM August 13, 2019",
number_likes: 0,
comments: []
},
{
imageSrc: "./images/holiday-party.png",
caption: "What a great holiday party omg",
timestamp: "11:37 PM December 31, 2019",
number_likes: 13,
comments: []
}
];
console.log(posts);
console.log(posts[0]);
// The code snippet above shows an Array with 2 elements. Each element in the Array is a
// Objects. Each of those Objects has 4 key-value pairs. This may LOOK
// a bit daunting - it's OK! You don't need to be 100% comfortable with this, but it's
// good to have some exposure before going into Mod 1.
// YOU DO: Create an array of at least 3 EMAIL Objects, using the same
// key-value pairs you used in your email Object above.
// Then, print the email Array to the Terminal.