forked from DevMountain/javascript-2-afternoon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice.js
More file actions
185 lines (134 loc) · 4.3 KB
/
practice.js
File metadata and controls
185 lines (134 loc) · 4.3 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
Once you complete a problem, refresh ./SpecRunner.html in your browser and check to see if the problem's test(s) are passing.
Passed tests will be indicated by a green circle.
Failed tests will be indicated by a red X.
You can refresh the page at any time to re-run all the tests.
*/
////////// PROBLEM 1 //////////
/*
Create an object called me.
Give it a key of name with the value being your name, and another key of age with the value being your age.
Then alert your name using dot notation.
*/
//Code here
const me = {
name: 'shaun',
age: 31
}
// alert(me.name);
////////// PROBLEM 2 //////////
/*
Make a 'favoriteThings' object that contains the following keys: band, food, person, book, movie, holiday.
Have the values to those keys be your favorite thing in that category.
*/
//Code here
const favoriteThings = {
band: 'band',
food: 'food',
person: 'person',
book: 'book',
movie: 'movie',
holiday: 'holiday'
}
/*
After you've made your object, add another key named 'car' with the value being your favorite car and then another key named 'brand' with the value being your favorite brand.
*/
//Code here
favoriteThings.car = 'car';
favoriteThings.brand = 'brand';
/*
Now change the value of the food key in your favoriteThings object to be 'Chicken Nuggets' and change the value of the book key in your favoriteThings object to be 'Harry Potter'.
*/
//Code here
favoriteThings.food = 'Chicken Nuggets';
favoriteThings.book = 'Harry Potter';
////////// PROBLEM 3 //////////
/*
Create an empty Object called backPack.
Now, create a variable called 'item' and set it equal to the string 'firstPocket'.
Using bracket notation, add a 'firstPocket' key (or property) to backPack, using 'item'.
Set the value of that key to 'chapstick'.
Using dot notation, add another key (or property) to your backPack object that is named color, with the value being the color of your backPack.
*/
//Code here
const backPack = {};
const item = 'firstPocket';
backPack[item] = 'chapstick';
/*
After you do the above, alert your entire backPack object.
*/
//Code here
// alert(backPack);
/*
You probably noticed that it just alerted [object Object].
Alerting to see the data in your Object doesn't work so well.
Instead, console.log your whole backPack object and then check out the console.
*/
//Code here
console.log(backPack);
////////// PROBLEM 4 //////////
// Do not edit the code below.
var user2 = {
name: 'Ty',
age: 24,
pwHash: 'U+Ldlngx2BYQk',
email: 'ty33@gmail.com',
birthday: '05/02/1990',
username: 'tylermcginnis33'
};
// Do not edit the code above.
/*
Let's say I, the user, decided to change my name and email address to the following:
name -> 'Tyler S. McGinnis' and email -> 'tyler.mcginnis@devmounta.in'.
Make that change without modifying the original object code above.
*/
//Code Here
user2.name = 'Tyler S. McGinnis';
user2.email = 'tyler.mcginnis@devmounta.in';
/////////////////////// EXTRA PRACTICE PROBLEMS BELOW ////////////////////
////////// MOVE ONTO NEXT SECTION BEFORE WORKING ON THESE ////////////////
////////// PROBLEM 5 //////////
/*
Create an empty object called methodCollection.
*/
//Code Here
methodCollection = {};
/*
Now add two methods (functions that are properties on objects) to your methodCollection object.
One called 'alertHello' which alerts 'hello' and another method called 'logHello' which logs 'hello' to the console.
*/
//Code Here
methodCollection.alertHello = function() {alert('hello')};
methodCollection.logHello = () => console.log('hello');
/*
Now call your alertHello and logHello methods.
*/
//Code Here
// methodCollection.alertHello();
// methodCollection.logHello();
////////// PROBLEM 6 //////////
/*
Create a function called makePerson which takes in name, birthday, ssn as its parameters.
Return a new object with all of the information that you passed in.
*/
//Code Here
function makePerson (name, birthday, ssn) {
return {
name,
birthday,
ssn
}
}
////////// PROBLEM 7 //////////
/*
Create a function called makeCard which takes in cardNumber, expirationDate, and securityCode to make a Credit Card object.
Return that object so that whenever you invoke makeCard, you get a brand new credit card.
*/
//Code Here
function makeCard(cardNumber, expirationDate, securityCode) {
return {
cardNumber,
expirationDate,
securityCode
}
}