forked from DevMountain/javascript-3-afternoon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforInLoops_Delete.js
More file actions
121 lines (63 loc) · 3.23 KB
/
forInLoops_Delete.js
File metadata and controls
121 lines (63 loc) · 3.23 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
// ========================
// FOR IN LOOPS & OBJECT DELETE
// ========================
// 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)
// }
// ========================
// 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
}
// ========================
// 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
// ========================
// 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
// ========================
// 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)
// ========================
// Write a function called removePassword that takes in an object. Delete the property password and return the object.
// CODE HERE
// ========================
// Write a for in loop that deletes every property from the object deleteTheBigNumbers whose value is greater than 100.
var deleteTheBigNumbers = {
first: 10,
second: 20,
third: 110,
fourth: 200
}
// CODE HERE
// ========================
// 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
// ========================
// 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