forked from DevMountain/javascript-2-afternoon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
practice.js
146 lines (115 loc) · 3.95 KB
/
practice.js
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
/*
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: 'Jordon Trower',
age: 18
};
// //////// 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: 'Siivagunner',
food: 'Rice',
person: 'Uhhh',
book:
'That one really long smash bros fanfic that holds the title of worlds longest literature',
movie: 'AAA',
holiday: 'aaa'
};
/*
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 = '1996 NA Miata';
favoriteThings.brand = 'Mazda';
/*
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'.
*/
favoriteThings.food = 'Chicken Nuggets';
favoriteThings.book = 'Harry Potter';
// Code here
// //////// 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';
backPack.color = 'black & red';
/*
After you do the above, alert your entire backPack object.
*/
alert(backPack);
// Code here
/*
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.
const user2 = {
name: 'Ty',
age: 24,
pwHash: 'U+Ldlngx2BYQk',
email: '[email protected]',
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 -> '[email protected]'.
Make that change without modifying the original object code above.
*/
// Code Here
user2.name = 'Tyler S. McGinnis';
user2.email = '[email protected]';
// //////// EXTRA PRACTICE PROBLEMS BELOW //////////
// //////// PROBLEM 5 //////////
/*
Create an empty object called methodCollection.
*/
// Code Here
/*
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
/*
Now call your alertHello and logHello methods.
*/
// Code Here
// //////// 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
// //////// 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