Skip to content

Commit 573fa9a

Browse files
Alex WeiksnarAlex Weiksnar
authored andcommitted
70 koans
1 parent 50d60ad commit 573fa9a

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

topics/about_functions_and_closure.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ test("defining functions directly", function() {
77
result = "b";
88
};
99
changeResult();
10-
equal(__, result, 'what is the value of result?');
10+
equal("b", result, 'what is the value of result?');
1111
});
1212

1313
test("assigning functions to variables", function() {
1414
var triple = function(input) {
1515
return input * 3;
1616
};
17-
equal(__, triple(4), 'what is triple 4?');
17+
equal(12, triple(4), 'what is triple 4?');
1818
});
1919

2020
test("self invoking functions", function() {
@@ -23,23 +23,23 @@ test("self invoking functions", function() {
2323
// self invoking functions are used to provide scoping and to alias variables
2424
(function(pv) {
2525
var secretValue = "password";
26-
equal(__, pv, 'what is the value of pv?');
27-
equal("__", typeof(secretValue), "is secretValue available in this context?");
28-
equal("__", typeof(publicValue), "is publicValue available in this context?");
26+
equal("shared", pv, 'what is the value of pv?');
27+
equal("string", typeof(secretValue), "is secretValue available in this context?");
28+
equal("string", typeof(publicValue), "is publicValue available in this context?");
2929
})(publicValue);
3030

31-
equal("__", typeof(secretValue), "is secretValue available in this context?");
32-
equal("__", typeof(publicValue), "is publicValue available in this context?");
31+
equal("undefined", typeof(secretValue), "is secretValue available in this context?");
32+
equal("string", typeof(publicValue), "is publicValue available in this context?");
3333
});
3434

3535
test("arguments array", function() {
3636
var add = function() {
3737
var total = 0;
3838
for(var i = 0; i < arguments.length; i++) {
3939
// complete the implementation of this method so that it returns the sum of its arguments
40-
// __
40+
total += arguments[i]
4141
}
42-
// __
42+
return total
4343
};
4444

4545
equal(15, add(1,2,3,4,5), "add 1,2,3,4,5");
@@ -57,7 +57,7 @@ test("using call to invoke function",function(){
5757
//function, and the arguments to be sent to the function,multiple arguments are separated by commas.
5858
var result = invokee.call("I am this!", "Where did it come from?");
5959

60-
equal(__, result, "what will the value of invokee's this be?");
60+
equal("I am this!Where did it come from?", result, "what will the value of invokee's this be?");
6161
});
6262

6363
test("using apply to invoke function",function(){
@@ -70,6 +70,6 @@ test("using apply to invoke function",function(){
7070
//function and and array of arguments to be passed into the called function.
7171
var result = invokee.apply("I am this!", ["I am arg1","I am arg2"]);
7272

73-
equal(__, result, "what will the value of invokee's this be?");
73+
equal("I am this!I am arg1I am arg2", result, "what will the value of invokee's this be?");
7474
});
7575

topics/about_scope.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module("About Scope (topics/about_scope.js)");
33
thisIsAGlobalVariable = 77;
44

55
test("global variables", function() {
6-
equal(__, thisIsAGlobalVariable, 'is thisIsAGlobalVariable defined in this scope?');
6+
equal(77, thisIsAGlobalVariable, 'is thisIsAGlobalVariable defined in this scope?');
77
});
88

99
test("variables declared inside of a function", function() {
@@ -12,10 +12,10 @@ test("variables declared inside of a function", function() {
1212
// this is a self-invoking function. Notice that it calls itself at the end ().
1313
(function() {
1414
var innerVariable = "inner";
15-
equal(__, outerVariable, 'is outerVariable defined in this scope?');
16-
equal(__, innerVariable, 'is innerVariable defined in this scope?');
15+
equal("outer", outerVariable, 'is outerVariable defined in this scope?');
16+
equal("inner", innerVariable, 'is innerVariable defined in this scope?');
1717
})();
1818

19-
equal(__, outerVariable, 'is outerVariable defined in this scope?');
20-
equal(__, typeof(innerVariable), 'is innerVariable defined in this scope?');
19+
equal("outer", outerVariable, 'is outerVariable defined in this scope?');
20+
equal(undefined, typeof(innerVariable), 'is innerVariable defined in this scope?');
2121
});

topics/about_this.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ test("'this' inside a method", function () {
44
var person = {
55
name: 'bob',
66
intro: function () {
7-
return "Hello, my name is " + this.__;
7+
return "Hello, my name is " + this.name;
88
}
99
}
1010
equal(person.intro(), "Hello, my name is bob", "If an object has a method can you access properties inside it?");
@@ -22,7 +22,7 @@ test("'this' on unattached function", function () {
2222

2323
// if the function is not called as an object property 'this' is the global context
2424
// (window in a browser). This is an example. Please do not do this in practise.
25-
window.__ = 'Peter';
25+
window.globalName = 'Peter';
2626
equal(alias(), "Hello, my name is Peter", "What does 'this' referer to when it is not part of an object?");
2727
});
2828

@@ -35,7 +35,7 @@ test("'this' set explicitly", function () {
3535
}
3636

3737
// calling a function with 'call' lets us assign 'this' explicitly
38-
var message = person.intro.call({__: "Frank"});
38+
var message = person.intro.call({name: "Frank"});
3939
equal(message, "Hello, my name is Frank", "What does 'this' referer to when you use the 'call()' method?");
4040
});
4141

0 commit comments

Comments
 (0)