forked from DevMountain/javascript-1-afternoon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
practice.js
204 lines (100 loc) · 4.26 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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
//=========DO NOT TOUCH THIS CODE=========//
var greetingsEarthlings = { greeting, newGreeting, finalGreeting }
//============Continue below=============//
//+++++++++ Start Here! All problems are below. +++++++++//
//////////////////PROBLEM 1////////////////////
//Create a function declaration called greeting that
//accepts name as its only parameter.
//greeting should return the string "Hello, "
//plus the value of the name parameter.
//Code here
//////////////////PROBLEM 2////////////////////
//Rewrite the function greeting as a function expression.
//Name it newGreeting (You must use a var for this instead of let or const)
//Code Here
//////////////////PROBLEM 3////////////////////
//Rewrite the function greeting as an arrow function.
//Name it finalGreeting (You must use a var for this instead of let or const)
//Code Here
//////////////////PROBLEM 4////////////////////
//Create an array called groceries with the values
//"apples", "milk", "eggs", "bread"
//Code Here
//Write a function called doubleCheck that takes in an array
//as a parameter.
//If the array does not contain "chocolate", add "chocolate".
//doubleCheck should return the array.
//Code Here
//////////////////PROBLEM 5////////////////////
//Create an object saved to the variable dog.
//The dog object should have the following properties:
//name (a string), color: (a string), age (a number),
//and goodBoy (a boolean).
//Code Here
//...access the dog's name from the object and assign it to a
//variable called devMountainClassPet.
//Code Here
//Add a method to dog called bark.
//The value of bark should be a function that returns the string "Woof woof"
//Code Here
//Store the result of invoking the bark method in a variable called ruff
//Code Here
//////////////////PROBLEM 6////////////////////
//Write a function called looper that takes in an array. looper should declare
//a variable called mySum. looper should then loop through the array and check
//each element.
//If the element is odd, or if the element is greater than or equal to 100, add the element
//to mySum.
//Return mySum.
//Code Here
//////////////////PROBLEM 7////////////////////
//Given the following function called math
function math(num1, num2, callback) {
return callback(num1, num2)
}
//Write a function called add that takes in two parameters and
//returns the result of adding them together.
//Code Here
//Now invoke math, passing in the numbers 3 and 4, and your add function,
//storing the result in the variable mathSum
//Code Here
//////////////////PROBLEM 8////////////////////
//Write a function called invoker that takes in one paramter, a callback function.
//invoker should return the result of invoking the callback.
function sampleCallbackOne() {
return 'I am a callback function'
}
function sampleCallbackTwo() {
return 'I am also a callback function'
}
//Code Here
//////////////////PROBLEM 9////////////////////
let duck = 'cute';
function bathroom () {
let rubberDuck = 'squeaky';
function bathtub() {
let sailorDuck = 'nautical';
}
}
function pond() {
let realDuck = 'fluffy';
}
//Given the functions and variables above, edit the arrays
//below to contain only the appropriate variable names
//as strings
//This array should contain the variable names (as strings) accessible in the global scope.
let globalScope = ['duck', 'sailorDuck', 'rubberDuck', 'realDuck'];
//This array should contain the variable names (as strings) accessible in the bathroom function.
let bathroomScope = ['duck', 'sailorDuck', 'rubberDuck', 'realDuck'];
//This array should contain the variable names (as strings) accessible in the bathtub function.
let bathtubScope = ['duck', 'sailorDuck', 'rubberDuck', 'realDuck'];
//This array should contain the variable names (as strings) accessible in the pond function.
let pondScope = ['duck', 'sailorDuck', 'rubberDuck', 'realDuck'];
//////////////////PROBLEM 10////////////////////
//Create a function called outerFn which returns an anonymous
//function which returns your name.
//Code Here
//Now save the result of invoking outerFn into a variable called innerFn.
//Code Here
//Now invoke innerFn and save the result to a variable called finalResult.
//Code Here