forked from devleague/js-scope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscope.js
66 lines (52 loc) · 1.53 KB
/
scope.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
// Fill in the closeLid and openLid functions to set the isCookieJarOpen variable to false or true respectively.
var isCookieJarOpen = null;
function closeLid() {
/* answer here */
}
function openLid() {
/* answer here */
}
// Fill in the return value for the inner function to return a string, 'Hello World' using only the variables provided
// in both inner and outer functions
function outerFunction() {
var hello = 'Hello';
function innerFunction() {
var world = 'World';
return /* answer here */;
}
return innerFunction();
}
// This is a function that takes in a 2d-array (or matrix) and returns the sum of all elements
// It's broken due to count variables colliding into each other. Fix it!
function addMatrixElements(matrix) {
var result = 0;
for(var i = 0; i < matrix.length; i++) {
/* fix counter variables in the second loop */
for(var i = 0; i < matrix[i].length; i++) {
result = result + matrix[i][i];
}
}
return result;
}
// This function is returning the wrong userObject data. It should be returning
// Neo's information and not Morpheus'. Fix it!
function sendDataToClient() {
var userObject = {
handle: 'neo',
authenticated: false
}
function authenticateUser(obj, username) {
var userObject = {
handle: 'morpheus',
authenticated: false
};
if (userObject.handle === username) {
userObject.authenticated = true;
return userObject
} else {
return userObject
}
}
authenticateUser(userObject, 'neo')
return userObject
}