From c0ea85b3dfaf2a30e0f6655e0c5e8beef644b1b1 Mon Sep 17 00:00:00 2001 From: Andre deVerteuil Date: Sun, 11 Nov 2012 22:14:40 -0500 Subject: [PATCH 1/2] Koans completed with a few equals flipped to equal for fun --- topics/about_arrays.js | 20 +++++++++--------- topics/about_asserts.js | 6 +++--- topics/about_assignment.js | 4 ++-- topics/about_control_structures.js | 16 +++++++-------- topics/about_equality.js | 10 ++++----- topics/about_functions_and_closure.js | 21 ++++++++++--------- topics/about_numbers.js | 11 +++++----- topics/about_objects.js | 22 ++++++++++---------- topics/about_operators.js | 10 ++++----- topics/about_prototypal_inheritance.js | 10 ++++----- topics/about_prototype_chain.js | 16 +++++++-------- topics/about_reflection.js | 28 +++++++++++++------------- topics/about_regular_expressions.js | 10 ++++----- topics/about_scope.js | 8 ++++---- topics/about_strings.js | 12 +++++------ topics/about_this.js | 6 +++--- topics/about_truthyness.js | 8 ++++---- 17 files changed, 110 insertions(+), 108 deletions(-) diff --git a/topics/about_arrays.js b/topics/about_arrays.js index 9e32f400..08408fe9 100644 --- a/topics/about_arrays.js +++ b/topics/about_arrays.js @@ -3,25 +3,25 @@ module("About Arrays (topics/about_arrays.js)"); test("array literal syntax and indexing", function() { var favouriteThings = ["cellar door", 42, true]; // note that array elements do not have to be of the same type - equals(favouriteThings[0], __, 'what is in the first position of the array?'); - equals(favouriteThings[1], __, 'what is in the second position of the array?'); - equals(favouriteThings[2], __, 'what is in the third position of the array?'); + equals(favouriteThings[0], "cellar door", 'what is in the first position of the array?'); + equals(favouriteThings[1], 42, 'what is in the second position of the array?'); + equals(favouriteThings[2], true, 'what is in the third position of the array?'); }); test("array type", function() { - equals(typeof([]), __, 'what is the type of an array?'); + equals(typeof([]), "object", 'what is the type of an array?'); }); test("length", function() { var collection = ['a','b','c']; - equals(collection.length, __, 'what is the length of the collection array?'); + equals(collection.length, 3, 'what is the length of the collection array?'); }); test("splice", function() { var daysOfWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']; - var workingWeek = daysOfWeek.splice(__, __); - ok(workingWeek.equalTo([__]), 'what is the value of workingWeek?'); - ok(daysOfWeek.equalTo([__]), 'what is the value of daysOfWeek?'); + var workingWeek = daysOfWeek.splice(0, 5); + ok(workingWeek.equalTo(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']), 'what is the value of workingWeek?'); + ok(daysOfWeek.equalTo([ 'Saturday', 'Sunday']), 'what is the value of daysOfWeek?'); }); test("stack methods", function() { @@ -29,6 +29,6 @@ test("stack methods", function() { stack.push("first"); stack.push("second"); - equals(stack.pop(), __, 'what will be the first value popped off the stack?'); - equals(stack.pop(), __, 'what will be the second value popped off the stack?'); + equals(stack.pop(), 'second', 'what will be the first value popped off the stack?'); + equals(stack.pop(), 'first', 'what will be the second value popped off the stack?'); }); diff --git a/topics/about_asserts.js b/topics/about_asserts.js index f94dde46..db3828f1 100644 --- a/topics/about_asserts.js +++ b/topics/about_asserts.js @@ -2,13 +2,13 @@ module("About Asserts (topics/about_asserts.js)"); test("ok", function() { - ok(__, 'what will satisfy the ok assertion?'); + ok(true, 'what will satisfy the ok assertion?'); }); test("not", function() { - not(__, 'what is a false value?'); + notEqual(true, false, 'what is a false value?'); }); test("equals", function() { - equals(1+1, __, 'what will satisfy the equals assertion?'); + equal(1+1, 2, 'what will satisfy the equals assertion?'); }); diff --git a/topics/about_assignment.js b/topics/about_assignment.js index 3b5c9831..84b5809f 100644 --- a/topics/about_assignment.js +++ b/topics/about_assignment.js @@ -2,11 +2,11 @@ module("About Assignment (topics/about_assignment.js)"); test("local variables", function() { - var temp = __; + var temp = 1; equals(1, temp, "Assign a value to the variable temp"); }); test("global variables", function() { temp = 1; - equals(temp, window.__, 'global variables are assigned to the window object'); + equals(temp, window.temp, 'global variables are assigned to the window object'); }); diff --git a/topics/about_control_structures.js b/topics/about_control_structures.js index 8d2007df..e9102ccf 100644 --- a/topics/about_control_structures.js +++ b/topics/about_control_structures.js @@ -5,7 +5,7 @@ test("if", function() { if (2 > 0) { isPositive = true; } - equals(isPositive, __, 'what is the value of isPositive?'); + equals(isPositive, true, 'what is the value of isPositive?'); }); test("for", function() { @@ -13,7 +13,7 @@ test("for", function() { for (var i = 1; i <= 3; i++) { counter = counter + i; } - equals(counter, __, 'what is the value of counter?'); + equals(counter, 16, 'what is the value of counter?'); }); test("for in", function() { @@ -27,15 +27,15 @@ test("for in", function() { for (property_name in person) { result = result + property_name; }; - equals(result, __, 'what is the value of result?'); + equals(result, 'nameage', 'what is the value of result?'); }); test("ternary operator", function() { var fruit = true ? "apple" : "orange"; - equals(fruit, __, 'what is the value of fruit?'); + equals(fruit, 'apple', 'what is the value of fruit?'); fruit = false ? "apple" : "orange"; - equals(fruit, __, 'now what is the value of fruit?'); + equals(fruit, 'orange', 'now what is the value of fruit?'); }); test("switch", function() { @@ -48,7 +48,7 @@ test("switch", function() { result = 2; break; } - equals(result, __, 'what is the value of result?'); + equals(result, 2, 'what is the value of result?'); }); test("switch default case", function() { @@ -64,10 +64,10 @@ test("switch default case", function() { result = "Merry"; break; } - equals(result, __, 'what is the value of result?'); + equals(result, 'Merry', 'what is the value of result?'); }); test("null coalescing", function() { var result = null || "a value"; - equals(result, __, 'what is the value of result?'); + equals(result, 'a value', 'what is the value of result?'); }); diff --git a/topics/about_equality.js b/topics/about_equality.js index 797a653e..7b952eef 100644 --- a/topics/about_equality.js +++ b/topics/about_equality.js @@ -2,21 +2,21 @@ module("About Equality (topics/about_equality.js)"); test("numeric equality", function() { - equals(3 + __, 7, 'hmmmm?'); + equals(3 + 4, 7, 'hmmmm?'); }); test("string equality", function() { - equals("3" + __, "37", "concatenate the strings"); + equals("3" + "7", "37", "concatenate the strings"); }); test("equality without type coercion", function() { - ok(3 === __, 'what is exactly equal to 3?'); + ok(3 === 3, 'what is exactly equal to 3?'); }); test("equality with type coercion", function() { - ok(3 == "__", 'what string is equal to 3, with type coercion?'); + ok(3 == "3", 'what string is equal to 3, with type coercion?'); }); test("string literals", function() { - equals("frankenstein", '__', "quote types are interchangable, but must match."); + equal("frankenstein", 'frankenstein', "quote types are interchangable, but must match."); }); diff --git a/topics/about_functions_and_closure.js b/topics/about_functions_and_closure.js index 04a22b91..eda7301d 100644 --- a/topics/about_functions_and_closure.js +++ b/topics/about_functions_and_closure.js @@ -7,14 +7,14 @@ test("defining functions directly", function() { result = "b"; }; changeResult(); - equals(result, __, 'what is the value of result?'); + equals(result, 'b', 'what is the value of result?'); }); test("assigning functions to variables", function() { var triple = function(input) { return input * 3; }; - equals(triple(4), __, 'what is triple 4?'); + equals(triple(4), 12, 'what is triple 4?'); }); test("self invoking functions", function() { @@ -23,13 +23,13 @@ test("self invoking functions", function() { // self invoking functions are used to provide scoping and to alias variables (function(pv) { var secretValue = "password"; - equals(pv, __, 'what is the value of pv?'); - equals(typeof(secretValue), "__", "is secretValue available in this context?"); - equals(typeof(publicValue), "__", "is publicValue available in this context?"); + equals(pv, "shared", 'what is the value of pv?'); + equals(typeof(secretValue), "string", "is secretValue available in this context?"); + equals(typeof(publicValue), "string", "is publicValue available in this context?"); })(publicValue); - equals(typeof(secretValue), "__", "is secretValue available in this context?"); - equals(typeof(publicValue), "__", "is publicValue available in this context?"); + equals(typeof(secretValue), "undefined", "is secretValue available in this context?"); + equals(typeof(publicValue), "string", "is publicValue available in this context?"); }); test("arguments array", function() { @@ -38,8 +38,9 @@ test("arguments array", function() { for(var i = 0; i < arguments.length; i++) { // complete the implementation of this method so that it returns the sum of its arguments // __ + total += arguments[i]; } - // __ + return total; }; equals(add(1,2,3,4,5), 15, "add 1,2,3,4,5"); @@ -57,7 +58,7 @@ test("using call to invoke function",function(){ //function, and the arguments to be sent to the function,multiple arguments are separated by commas. var result = invokee.call("I am this!", "Where did it come from?"); - equals(result,__,"what will the value of invokee's this be?"); + equals(result,"I am this!Where did it come from?","what will the value of invokee's this be?"); }); test("using apply to invoke function",function(){ @@ -70,6 +71,6 @@ test("using apply to invoke function",function(){ //function and and array of arguments to be passed into the called function. var result = invokee.apply("I am this!", ["I am arg1","I am arg2"]); - equals(result,__,"what will the value of invokee's this be?"); + equals(result,"I am this!I am arg1I am arg2","what will the value of invokee's this be?"); }); diff --git a/topics/about_numbers.js b/topics/about_numbers.js index 672f3318..1b3476b7 100644 --- a/topics/about_numbers.js +++ b/topics/about_numbers.js @@ -4,13 +4,14 @@ module("About Numbers (topics/about_numbers.js)"); test("types", function() { var typeOfIntegers = typeof(6); var typeOfFloats = typeof(3.14159); - equals(typeOfIntegers === typeOfFloats, __, 'are ints and floats the same type?'); - equals(typeOfIntegers, __, 'what is the javascript numeric type?'); - equals(1.0, __, 'what is a integer number equivalent to 1.0?'); + + equals(typeOfIntegers === typeOfFloats, true, 'are ints and floats the same type?'); + equals(typeOfIntegers, "number" , 'what is the javascript numeric type?'); + equals(1.0, 1, 'what is a integer number equivalent to 1.0?'); }); test("NaN", function() { var resultOfFailedOperations = 7/'apple'; - equals(isNaN(resultOfFailedOperations), __, 'what will satisfy the equals assertion?'); - equals(resultOfFailedOperations == NaN, __, 'is NaN == NaN?'); + equals(isNaN(resultOfFailedOperations), true, 'what will satisfy the equals assertion?'); + equals(resultOfFailedOperations == NaN, false, 'is NaN == NaN?'); }); diff --git a/topics/about_objects.js b/topics/about_objects.js index 35185b32..60f0c210 100644 --- a/topics/about_objects.js +++ b/topics/about_objects.js @@ -3,30 +3,30 @@ module("About Objects (topics/about_objects.js)"); test("object type", function() { var empty_object = {}; - equals(typeof(empty_object), __, 'what is the type of an object?'); + equals(typeof (empty_object), "object", 'what is the type of an object?'); }); test("object literal notation", function() { var person = { - __:__, - __:__ - }; - equals(person.name, "Amory Blaine", 'what is the person\'s name?'); - equals(person.age, 102, 'what is the person\'s age?'); + name: "Amory Blaine", + age: 102 + }; + equal(person.name, "Amory Blaine", 'what is the person\'s name?'); + equal(person.age, 102, 'what is the person\'s age?'); }); test("dynamically adding properties", function() { var person = {}; - person.__ = "Amory Blaine"; - person.__ = 102; + person.name = "Amory Blaine"; + person.age = 102; equals(person.name, "Amory Blaine", 'what is the person\'s name?'); equals(person.age, 102, 'what is the person\'s age?'); }); test("adding properties from strings", function() { var person = {}; - person["__"] = "Amory Blaine"; - person["__"] = 102; + person["name"] = "Amory Blaine"; + person["age"] = 102; equals(person.name, "Amory Blaine", 'what is the person\'s name?'); equals(person.age, 102, 'what is the person\'s age?'); }); @@ -36,7 +36,7 @@ test("adding functions", function() { name: "Amory Blaine", age: 102, toString: function() { - return __; // HINT: use the 'this' keyword to refer to the person object. + return 'I ' + person.name + ' am ' + person.age + ' years old.'; // HINT: use the 'this' keyword to refer to the person object. } }; equals(person.toString(), "I Amory Blaine am 102 years old.", 'what should the toString function be?'); diff --git a/topics/about_operators.js b/topics/about_operators.js index 09df716b..60b22a70 100644 --- a/topics/about_operators.js +++ b/topics/about_operators.js @@ -7,7 +7,7 @@ test("addition", function() { for (var i = 0; i <= 5; i++) { result = result + i; } - equals(result, __, "What is the value of result?"); + equal(result, 15, "What is the value of result?"); }); test("assignment addition", function() { @@ -16,7 +16,7 @@ test("assignment addition", function() { //the code below is just like saying result = result + i; but is more concise result += i; } - equals(result, __, "What is the value of result?"); + equal(result, 15, "What is the value of result?"); }); test("subtraction", function() { @@ -24,7 +24,7 @@ test("subtraction", function() { for (var i = 0; i <= 2; i++) { result = result - i; } - equals(result, __, "What is the value of result?"); + equal(result, 2, "What is the value of result?"); }); test("assignment subtraction", function() { @@ -32,7 +32,7 @@ test("assignment subtraction", function() { for (var i = 0; i <= 2; i++) { result -= i; } - equals(result, __, "What is the value of result?"); + equal(result, 2, "What is the value of result?"); }); //Assignment operators are available for multiplication and division as well @@ -43,5 +43,5 @@ test("modulus", function() { var x = 5; //again this is exactly the same as result = result % x result %= x; - equals(result, __, "What is the value of result?"); + equals(result, 0, "What is the value of result?"); }); diff --git a/topics/about_prototypal_inheritance.js b/topics/about_prototypal_inheritance.js index 23b7386c..6b355bb8 100644 --- a/topics/about_prototypal_inheritance.js +++ b/topics/about_prototypal_inheritance.js @@ -16,7 +16,7 @@ Mammal.prototype = { test("defining a 'class'", function() { var eric = new Mammal("Eric"); - equals(eric.sayHi(), __, 'what will Eric say?'); + equals(eric.sayHi(), "Hello, my name is Eric", 'what will Eric say?'); }); // add another function to the Mammal 'type' that uses the sayHi function @@ -26,7 +26,7 @@ Mammal.prototype.favouriteSaying = function() { test("more functions", function() { var bobby = new Mammal("Bobby"); - equals(bobby.favouriteSaying(), __, "what is Bobby's favourite saying?"); + equals(bobby.favouriteSaying(), "Bobby's favourite saying is Hello, my name is Bobby", "what is Bobby's favourite saying?"); }); test("calling functions added to a prototype after an object was created", function() { @@ -36,7 +36,7 @@ test("calling functions added to a prototype after an object was created", funct }; // the following statement asks the paul object to call a function that was added // to the Mammal prototype after paul was constructed. - equals(paul.numberOfLettersInName(), __, "how long is Paul's name?"); + equals(paul.numberOfLettersInName(), 4, "how long is Paul's name?"); }); // helper function for inheritance. @@ -56,6 +56,6 @@ extend(Bat, Mammal); test("Inheritance", function() { var lenny = new Bat("Lenny", "1.5m"); - equals(lenny.sayHi(), __, "what does Lenny say?"); - equals(lenny.wingspan, __, "what is Lenny's wingspan?"); + equals(lenny.sayHi(), "Hello, my name is Lenny" , "what does Lenny say?"); + equals(lenny.wingspan, "1.5m", "what is Lenny's wingspan?"); }); diff --git a/topics/about_prototype_chain.js b/topics/about_prototype_chain.js index cf9f11e1..eec046fa 100644 --- a/topics/about_prototype_chain.js +++ b/topics/about_prototype_chain.js @@ -27,29 +27,29 @@ child.b = 2; * */ test("Is there an 'a' and 'b' own property on child?", function () { - equals(child.hasOwnProperty('a'), __, 'child.hasOwnProperty(\'a\')?'); - equals(child.hasOwnProperty('b'), __, 'child.hasOwnProperty(\'b\')?'); + equals(child.hasOwnProperty('a'), true, 'child.hasOwnProperty(\'a\')?'); + equals(child.hasOwnProperty('b'), true, 'child.hasOwnProperty(\'b\')?'); }); test("Is there an 'a' and 'b' property on child?", function () { - equals(child.a, __, 'what is \'a\' value?'); - equals(child.b, __, 'what is \'b\' value?'); + equals(child.a, 1, 'what is \'a\' value?'); + equals(child.b, 2, 'what is \'b\' value?'); }); test("If 'b' was removed, whats b value?", function () { delete child.b; - equals(child.b, __, 'what is \'b\' value now?'); + equals(child.b, 3, 'what is \'b\' value now?'); }); test("Is there a 'c' own property on child?", function () { - equals(child.hasOwnProperty('c'), __, 'child.hasOwnProperty(\'c\')?'); + equals(child.hasOwnProperty('c'), false, 'child.hasOwnProperty(\'c\')?'); }); // Is there a 'c' own property on child? No, check its prototype // Is there a 'c' own property on child.[[Prototype]]? Yes, its value is... test("Is there a 'c' property on child?", function () { - equals(child.c, __, 'what is the value of child.c?'); + equals(child.c, 4, 'what is the value of child.c?'); }); @@ -57,7 +57,7 @@ test("Is there a 'c' property on child?", function () { // Is there a 'd' own property on child.[[Prototype]]? No, check it prototype // child.[[Prototype]].[[Prototype]] is null, stop searching, no property found, return... test("Is there an 'd' property on child?", function () { - equals(child.d, __, 'what is the value of child.d?'); + equals(child.d, undefined, 'what is the value of child.d?'); }); diff --git a/topics/about_reflection.js b/topics/about_reflection.js index 30b716c1..2828fc82 100644 --- a/topics/about_reflection.js +++ b/topics/about_reflection.js @@ -11,10 +11,10 @@ var B = function() { B.prototype = new A(); test("typeof", function() { - equals(typeof({}), __, 'what is the type of an empty object?'); - equals(typeof('apple'), __, 'what is the type of a string?'); - equals(typeof(-5), __, 'what is the type of -5?'); - equals(typeof(false), __, 'what is the type of false?'); + equals(typeof({}), 'object', 'what is the type of an empty object?'); + equals(typeof('apple'), 'string', 'what is the type of a string?'); + equals(typeof(-5), 'number', 'what is the type of -5?'); + equals(typeof(false), 'boolean', 'what is the type of false?'); }); test("property enumeration", function() { @@ -25,8 +25,8 @@ test("property enumeration", function() { keys.push(propertyName); values.push(person[propertyName]); } - ok(keys.equalTo(['__','__','__']), 'what are the property names of the object?'); - ok(values.equalTo(['__',__,__]), 'what are the property values of the object?'); + ok(keys.equalTo(['name','age','unemployed']), 'what are the property names of the object?'); + ok(values.equalTo(['Amory Blaine',102,true]), 'what are the property values of the object?'); }); test("hasOwnProperty", function() { @@ -36,8 +36,8 @@ test("hasOwnProperty", function() { for (propertyName in b) { keys.push(propertyName); } - equals(keys.length, __, 'how many elements are in the keys array?'); - ok(keys.equalTo([__, __]), 'what are the properties of the array?'); + equals(keys.length, 2, 'how many elements are in the keys array?'); + ok(keys.equalTo(['bprop', 'aprop']), 'what are the properties of the array?'); // hasOwnProperty returns true if the parameter is a property directly on the object, // but not if it is a property accessible via the prototype chain. @@ -47,21 +47,21 @@ test("hasOwnProperty", function() { ownKeys.push(propertyName); } } - equals(ownKeys.length, __, 'how many elements are in the ownKeys array?'); - ok(ownKeys.equalTo([__, __]), 'what are the own properties of the array?'); + equals(ownKeys.length, 1, 'how many elements are in the ownKeys array?'); + ok(ownKeys.equalTo(['bprop']), 'what are the own properties of the array?'); }); test("constructor property", function () { var a = new A(); var b = new B(); - equals(typeof(a.constructor), __, "what is the type of a's constructor?"); - equals(a.constructor.name, __, "what is the name of a's constructor?"); - equals(b.constructor.name, __, "what is the name of b's constructor?"); + equals(typeof(a.constructor), 'function', "what is the type of a's constructor?"); + equals(a.constructor.name, '', "what is the name of a's constructor?"); + equals(b.constructor.name, '', "what is the name of b's constructor?"); }); test("eval", function() { // eval executes a string var result = ""; eval("result = 'apple' + ' ' + 'pie'"); - equals(result, __, 'what is the value of result?'); + equals(result, 'apple pie', 'what is the value of result?'); }); diff --git a/topics/about_regular_expressions.js b/topics/about_regular_expressions.js index 8d409fca..762675df 100644 --- a/topics/about_regular_expressions.js +++ b/topics/about_regular_expressions.js @@ -4,28 +4,28 @@ module("About Regular Expressions (topics/about_regular_expressions.js)"); test("exec", function() { var numberFinder = /(\d).*(\d)/; var results = numberFinder.exec("what if 6 turned out to be 9?"); - ok(results.equalTo([__, __, __]), 'what is the value of results?'); + ok(results.equalTo(['6 turned out to be 9', '6', '9']), 'what is the value of results?'); }); test("test", function() { var containsSelect = /select/.test(" select * from users "); - equals(containsSelect, __, 'does the string provided contain "select"?'); + equals(containsSelect, true, 'does the string provided contain "select"?'); }); test("match", function() { var matches = "what if 6 turned out to be 9?".match(/(\d)/g); - ok(matches.equalTo([__, __]), 'what is the value of matches?'); + ok(matches.equalTo(['6', '9']), 'what is the value of matches?'); }); test("replace", function() { var pie = "apple pie".replace("apple", "strawberry"); - equals(pie, __, 'what is the value of pie?'); + equals(pie, 'strawberry pie', 'what is the value of pie?'); pie = "what if 6 turned out to be 9?".replace(/\d/g, function(number) { // the second parameter can be a string or a function var map = {'6': 'six','9': 'nine'}; return map[number]; }); - equals(pie, __, 'what is the value of pie?'); + equals(pie, 'what if six turned out to be nine?', 'what is the value of pie?'); }); // THE END diff --git a/topics/about_scope.js b/topics/about_scope.js index 3be52396..50cff60d 100644 --- a/topics/about_scope.js +++ b/topics/about_scope.js @@ -4,7 +4,7 @@ module("About Scope (topics/about_scope.js)"); thisIsAGlobalVariable = 77; test("global variables", function() { - equals(thisIsAGlobalVariable, __, 'is thisIsAGlobalVariable defined in this scope?'); + equals(thisIsAGlobalVariable, 77, 'is thisIsAGlobalVariable defined in this scope?'); }); test("variables declared inside of a function", function() { @@ -13,10 +13,10 @@ test("variables declared inside of a function", function() { // this is a self-invoking function. Notice that it calls itself at the end (). (function() { var innerVariable = "inner"; - equals(outerVariable, __, 'is outerVariable defined in this scope?'); - equals(innerVariable, __, 'is innerVariable defined in this scope?'); + equals(outerVariable, "outer", 'is outerVariable defined in this scope?'); + equals(innerVariable, "inner", 'is innerVariable defined in this scope?'); })(); - equals(outerVariable, __, 'is outerVariable defined in this scope?'); + equals(outerVariable, "outer", 'is outerVariable defined in this scope?'); equals(typeof(innerVariable), "undefined", 'is innerVariable defined in this scope?'); }); diff --git a/topics/about_strings.js b/topics/about_strings.js index 68fa6894..335d3f61 100644 --- a/topics/about_strings.js +++ b/topics/about_strings.js @@ -4,31 +4,31 @@ module("About Strings (topics/about_strings.js)"); test("delimiters", function() { var singleQuotedString = 'apple'; var doubleQuotedString = "apple"; - equals(singleQuotedString === doubleQuotedString, __, 'are the two strings equal?'); + equal(singleQuotedString === doubleQuotedString, true, 'are the two strings equal?'); }); test("concatenation", function() { var fruit = "apple"; var dish = "pie"; - equals(fruit + " " + dish, __, 'what is the value of fruit + " " + dish?'); + equals(fruit + " " + dish, "apple pie", 'what is the value of fruit + " " + dish?'); }); test("character Type", function() { var characterType = typeof("Amory".charAt(1)); // typeof will be explained in about reflection - equals(characterType, __, 'Javascript has no character type'); + equals(characterType, 'string', 'Javascript has no character type'); }); test("escape character", function() { var stringWithAnEscapedCharacter = "\u0041pple"; - equals(stringWithAnEscapedCharacter, __, 'what is the value of stringWithAnEscapedCharacter?'); + equal(stringWithAnEscapedCharacter, 'Apple', 'what is the value of stringWithAnEscapedCharacter?'); }); test("string.length", function() { var fruit = "apple"; - equals(fruit.length, __, 'what is the value of fruit.length?'); + equals(fruit.length, 5, 'what is the value of fruit.length?'); }); test("slice", function() { var fruit = "apple pie"; - equals(fruit.slice(0,5), __, 'what is the value of fruit.slice(0,5)?'); + equals(fruit.slice(0,5), 'apple', 'what is the value of fruit.slice(0,5)?'); }); diff --git a/topics/about_this.js b/topics/about_this.js index f1127556..e89741a6 100644 --- a/topics/about_this.js +++ b/topics/about_this.js @@ -4,7 +4,7 @@ test("'this' inside a method", function () { var person = { name: 'bob', intro: function () { - return "Hello, my name is " + this.__; + return "Hello, my name is " + this.name; } } equals(person.intro(), "Hello, my name is bob"); @@ -22,7 +22,7 @@ test("'this' on unattached function", function () { // if the function is not called as an object property 'this' is the global context // (window in a browser) - window.__ = 'Peter'; + window.name = 'Peter'; equals("Hello, my name is Peter", alias()); }); @@ -35,7 +35,7 @@ test("'this' set explicitly", function () { } // calling a function with 'call' lets us assign 'this' explicitly - var message = person.intro.call({__: "Frank"}); + var message = person.intro.call({name: "Frank"}); equals(message, "Hello, my name is Frank"); }); diff --git a/topics/about_truthyness.js b/topics/about_truthyness.js index 9c3f2319..e835fad5 100644 --- a/topics/about_truthyness.js +++ b/topics/about_truthyness.js @@ -3,20 +3,20 @@ module("About Truthyness (topics/about_truthyness.js)"); test("truthyness of positive numbers", function() { var oneIsTruthy = 1 ? true : false; - equals(oneIsTruthy, __, 'is one truthy?'); + equal(oneIsTruthy, true, 'is one truthy?'); }); test("truthyness of negative numbers", function() { var negativeOneIsTruthy = -1 ? true : false; - equals(negativeOneIsTruthy, __, 'is -1 truthy?'); + equals(negativeOneIsTruthy, true, 'is -1 truthy?'); }); test("truthyness of zero", function() { var zeroIsTruthy = 0 ? true : false; - equals(zeroIsTruthy, __, 'is 0 truthy?'); + equals(zeroIsTruthy, false, 'is 0 truthy?'); }); test("truthyness of null", function() { var nullIsTruthy = null ? true : false; - equals(nullIsTruthy, __, 'is null truthy?'); + equals(nullIsTruthy, false, 'is null truthy?'); }); From d281bf70b7d2189ce30299c66f27e701334bb72e Mon Sep 17 00:00:00 2001 From: Andre deVerteuil Date: Sun, 11 Nov 2012 22:17:03 -0500 Subject: [PATCH 2/2] Updated Readme with completed note --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 21c7fb79..edf47d2b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ +#Koans Completed + +These koans have been completed with notes attached. + +#JavaScript Koans + JavaScript Koans is an interactive learning environment that uses failing tests to introduce students to aspects of JavaScript in a logical sequence. The inspiration for this project comes from the Edgecase Ruby Koans and the book 'Javascript: The Good Parts'.