From 2726e0b34e6dba7616907f2ea2766ac5c7357b48 Mon Sep 17 00:00:00 2001 From: libra guest Date: Tue, 14 Aug 2012 05:22:03 -0400 Subject: [PATCH 01/10] First commit --- topics/about_asserts.js | 4 ++-- topics/about_equality.js | 10 +++++----- topics/about_operators.js | 10 +++++----- topics/about_truthyness.js | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/topics/about_asserts.js b/topics/about_asserts.js index f94dde46..970d5e6a 100644 --- a/topics/about_asserts.js +++ b/topics/about_asserts.js @@ -6,9 +6,9 @@ test("ok", function() { }); test("not", function() { - not(__, 'what is a false value?'); + not(false, 'what is a false value?'); }); test("equals", function() { - equals(1+1, __, 'what will satisfy the equals assertion?'); + equals(1+1, 2, 'what will satisfy the equals assertion?'); }); diff --git a/topics/about_equality.js b/topics/about_equality.js index 797a653e..2b1097af 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."); + equals("frankenstein", 'frankenstein', "quote types are interchangable, but must match."); }); diff --git a/topics/about_operators.js b/topics/about_operators.js index 09df716b..ed26e04d 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?"); + equals(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?"); + equals(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?"); + equals(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?"); + equals(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_truthyness.js b/topics/about_truthyness.js index 9c3f2319..4231ab6c 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?'); + equals(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 83f814d7c8cf181c9908e0e3fd9b4278e424f391 Mon Sep 17 00:00:00 2001 From: libra guest Date: Tue, 14 Aug 2012 05:24:09 -0400 Subject: [PATCH 02/10] Assigment done --- topics/about_assignment.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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'); }); From 7c258098d8129236aa37a9fb6c0c098de4af84c3 Mon Sep 17 00:00:00 2001 From: libra guest Date: Tue, 14 Aug 2012 07:12:15 -0400 Subject: [PATCH 03/10] Control done --- topics/about_control_structures.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/topics/about_control_structures.js b/topics/about_control_structures.js index 8d2007df..1fc9385f 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?'); }); From 0a4fe42997fe2c56f848970589881898bb2d349b Mon Sep 17 00:00:00 2001 From: libra guest Date: Tue, 14 Aug 2012 07:15:25 -0400 Subject: [PATCH 04/10] String done --- topics/about_strings.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/topics/about_strings.js b/topics/about_strings.js index 68fa6894..eb07ad23 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?'); + equals(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?'); + equals(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)?'); }); From 8478e7044fa60c6c8417ec120f67d952b0933396 Mon Sep 17 00:00:00 2001 From: libra guest Date: Tue, 14 Aug 2012 07:22:19 -0400 Subject: [PATCH 05/10] Number and objects done --- topics/about_numbers.js | 10 +++++----- topics/about_objects.js | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/topics/about_numbers.js b/topics/about_numbers.js index 672f3318..18296ea1 100644 --- a/topics/about_numbers.js +++ b/topics/about_numbers.js @@ -4,13 +4,13 @@ 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..59ec76b4 100644 --- a/topics/about_objects.js +++ b/topics/about_objects.js @@ -3,13 +3,13 @@ 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 = { - __:__, - __:__ + name:"Amory Blaine", + age:102 }; equals(person.name, "Amory Blaine", 'what is the person\'s name?'); equals(person.age, 102, 'what is the person\'s age?'); @@ -17,16 +17,16 @@ test("object literal notation", function() { 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 " + this.name + " am " + this.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?'); From 296f9b9c339513812630c7d54726fdfc9a079df6 Mon Sep 17 00:00:00 2001 From: libra guest Date: Tue, 14 Aug 2012 07:28:02 -0400 Subject: [PATCH 06/10] Arrays --- topics/about_arrays.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/topics/about_arrays.js b/topics/about_arrays.js index ab74a6c4..b706dbd2 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 poped off the stack?'); - equals(stack.pop(), __, 'what will be the second value poped off the stack?'); + equals(stack.pop(), "second", 'what will be the first value poped off the stack?'); + equals(stack.pop(), "first", 'what will be the second value poped off the stack?'); }); From 063a0b63d2db98d4640b31c78ff733f251b61e62 Mon Sep 17 00:00:00 2001 From: libra guest Date: Tue, 14 Aug 2012 07:35:29 -0400 Subject: [PATCH 07/10] Reflection --- topics/about_reflection.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/topics/about_reflection.js b/topics/about_reflection.js index 30b716c1..4b3a6721 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?'); }); From 5117108178cdb230c6b38c69a27a57335547ed18 Mon Sep 17 00:00:00 2001 From: libra guest Date: Tue, 14 Aug 2012 07:40:54 -0400 Subject: [PATCH 08/10] prototype chain --- topics/about_prototype_chain.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/topics/about_prototype_chain.js b/topics/about_prototype_chain.js index e215b8a7..b5e3847a 100644 --- a/topics/about_prototype_chain.js +++ b/topics/about_prototype_chain.js @@ -27,24 +27,24 @@ child.b = 2; * */ test("Is there an 'a' and 'b' own property on childObj?", 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?'); }); // Is there a 'c' own property on childObj? No, check its prototype // Is there a 'c' own property on childObj.[[Prototype]]? Yes, its value is... test("Is there a 'c' own property on childObj.[[Prototype]]?", function () { - equals(child.hasOwnProperty('c'), __, 'childObj.hasOwnProperty(\'c\')?'); + equals(child.hasOwnProperty('c'), false, 'childObj.hasOwnProperty(\'c\')?'); }); test("Is there a 'c' own property on childObj.[[Prototype]]?", function () { - equals(child.c, __, 'childObj.c?'); + equals(child.c, 4, 'childObj.c?'); }); @@ -52,7 +52,7 @@ test("Is there a 'c' own property on childObj.[[Prototype]]?", function () { // Is there a 'd' own property on childObj.[[Prototype]]? No, check it prototype // childObj.[[Prototype]].[[Prototype]] is null, stop searching, no property found, return... test("Is there an 'd' own property on childObj?", function () { - equals(child.d, __, 'what is the value of childObj.d?'); + equals(child.d, undefined, 'what is the value of childObj.d?'); }); From a0a3434c99b104cf485738a3c78ef2973280d4e6 Mon Sep 17 00:00:00 2001 From: libra guest Date: Tue, 14 Aug 2012 07:45:27 -0400 Subject: [PATCH 09/10] prototypal inheritance --- topics/about_prototypal_inheritance.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/topics/about_prototypal_inheritance.js b/topics/about_prototypal_inheritance.js index b2d152c6..54db0dd5 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() { @@ -35,7 +35,7 @@ test("calling functions added to a prototype after an object was created", funct return this.name.length; }; // for 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. @@ -55,6 +55,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?"); }); From 4dda57411c31f3a6edd429270e3eac69ef8695fe Mon Sep 17 00:00:00 2001 From: libra guest Date: Tue, 14 Aug 2012 11:20:45 -0400 Subject: [PATCH 10/10] functions --- topics/about_functions_and_closure.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/topics/about_functions_and_closure.js b/topics/about_functions_and_closure.js index 6b429cf1..596e7821 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() { @@ -37,14 +37,15 @@ test("arguments array", function() { var total = 0; 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"); equals(add(4,7,-2), 9, "add 4,7,-2"); }); - + test("using call to invoke function",function(){ var invokee = function( message ){ return this + message; @@ -56,7 +57,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(){ @@ -69,6 +70,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?"); });