forked from DevMountain/javascript-3-afternoon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
for-in-delete.js
162 lines (106 loc) · 3.58 KB
/
for-in-delete.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
Once you complete a problem, refresh ./for-in-delete.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.
*/
/*
First we'll look at the difference between accessing property values in a for in loop and accessing the property name in a for in loop.
In the example below, we are accessing the property values. Uncomment the code below, run it and look at what prints in the console.
*/
// var values = {
// one: 'These',
// two: ' are',
// three: ' the',
// four: ' property',
// five: ' values.'
// }
// for(var key in values) {
// console.log(values[key])
// }
/*
In this next example, we are accessing the property names themselves. Uncomment the code below, run it and look at what prints in the console.
*/
// for(var key in values) {
// console.log(key)
// }
////////// PROBLEM 1 //////////
/*
Inside the function showValues, write a for in loop that concatenates each of the property values and returns the concatenated string.
*/
function showValues( obj ) {
//Code Here
}
////////// PROBLEM 2 //////////
/*
Write a function called greaterThan10 that takes in an object.
Write a for in loop that loops over the object and changes any value that is great than 10 to 0.
Return the updated object.
*/
//Code Here
////////// PROBLEM 3 //////////
/*
Write a function called double that takes in an object.
Write a for in loop that loops over the object and changes every value to be itself multipled by 2.
Return the updated object.
*/
//Code Here
////////// PROBLEM 4 //////////
/*
Write a function called secrets that will take in an object.
Create an empty string variable.
Write a for in loop that loops over the object.
If the property name starts with an 'sh', concatenate the value to the string variable.
By the end of the for in loop, you should have a sentence, return that sentence.
*/
//Code Here
/*
Sometimes it's needed to delete object properties.
All you need is the word delete before a reference to the object property value.
Uncomment the example below to see a for in loop deleting all the properties inside an object.
*/
// var deleteAllThethings = {
// one: 1,
// two: 2,
// three: 3
// }
// for(var key in deleteAllThethings) {
// delete deleteAllThethings[key]
// }
// console.log(deleteAllThethings)
////////// PROBLEM 5 //////////
/*
Write a function called removePassword that takes in an object.
Delete the property password and return the object.
*/
//Code Here
////////// PROBLEM 6 //////////
// Do not edit the code below.
var deleteTheBigNumbers = {
first: 10,
second: 20,
third: 110,
fourth: 200
}
// Do not edit the code above.
/*
Write a for in loop that deletes every property from the object deleteTheBigNumbers whose value is greater than 100.
*/
//Code Here
////////// PROBLEM 7 //////////
/*
Write a function called startsWithK that takes an object as a parameter.
Write a for in loop to loop over the object.
If any property name starts with k, delete that property.
Return the updated object.
*/
//Code Here
////////// PROBLEM 8 //////////
/*
Write a function called hiddenTreasure that takes in an object.
Write a for in loop that loops over this object. Each property will have a sentence as it's value.
If the property value does not contain the word 'treasure', delete the property.
Return the updated object.
(hint: the method includes() may be of use...)
*/
//Code Here