Skip to content

Commit 309125b

Browse files
author
bruz
committed
complete
1 parent cd54550 commit 309125b

15 files changed

+93
-92
lines changed

topics/about_arrays.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@ module("About Arrays (topics/about_arrays.js)");
33

44
test("array literal syntax and indexing", function() {
55
var favouriteThings = ["cellar door", 42, true]; // note that array elements do not have to be of the same type
6-
equals(favouriteThings[0], __, 'what is in the first position of the array?');
7-
equals(favouriteThings[1], __, 'what is in the second position of the array?');
8-
equals(favouriteThings[2], __, 'what is in the third position of the array?');
6+
equals(favouriteThings[0], "cellar door", 'what is in the first position of the array?');
7+
equals(favouriteThings[1], 42, 'what is in the second position of the array?');
8+
equals(favouriteThings[2], true, 'what is in the third position of the array?');
99
});
1010

1111
test("array type", function() {
12-
equals(typeof([]), __, 'what is the type of an array?');
12+
equals(typeof([]), "object", 'what is the type of an array?');
1313
});
1414

1515
test("length", function() {
1616
var collection = ['a','b','c'];
17-
equals(collection.length, __, 'what is the length of the collection array?');
17+
equals(collection.length, 3, 'what is the length of the collection array?');
1818
});
1919

2020
test("splice", function() {
2121
var daysOfWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
22-
var workingWeek = daysOfWeek.splice(__, __);
23-
ok(workingWeek.equalTo([__]), 'what is the value of workingWeek?');
24-
ok(daysOfWeek.equalTo([__]), 'what is the value of daysOfWeek?');
22+
var workingWeek = daysOfWeek.splice(0, 5);
23+
ok(workingWeek.equalTo(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']), 'what is the value of workingWeek?');
24+
ok(daysOfWeek.equalTo(['Saturday', 'Sunday']), 'what is the value of daysOfWeek?');
2525
});
2626

2727
test("stack methods", function() {
2828
var stack = [];
2929
stack.push("first");
3030
stack.push("second");
3131

32-
equals(stack.pop(), __, 'what will be the first value poped off the stack?');
33-
equals(stack.pop(), __, 'what will be the second value poped off the stack?');
32+
equals(stack.pop(), "second", 'what will be the first value poped off the stack?');
33+
equals(stack.pop(), "first", 'what will be the second value poped off the stack?');
3434
});

topics/about_asserts.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
module("About Asserts (topics/about_asserts.js)");
33

44
test("ok", function() {
5-
ok(__, 'what will satisfy the ok assertion?');
5+
ok(true, 'what will satisfy the ok assertion?');
66
});
77

88
test("not", function() {
9-
not(__, 'what is a false value?');
9+
not(false, 'what is a false value?');
1010
});
1111

1212
test("equals", function() {
13-
equals(1+1, __, 'what will satisfy the equals assertion?');
13+
equals(1+1, 2, 'what will satisfy the equals assertion?');
1414
});

topics/about_assignment.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
module("About Assignment (topics/about_assignment.js)");
33

44
test("local variables", function() {
5-
var temp = __;
5+
var temp = 1;
66
equals(1, temp, "Assign a value to the variable temp");
77
});
88

99
test("global variables", function() {
1010
temp = 1;
11-
equals(temp, window.__, 'global variables are assigned to the window object');
11+
equals(temp, window.temp, 'global variables are assigned to the window object');
1212
});

topics/about_control_structures.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ test("if", function() {
66
if (2 > 0) {
77
isPositive = true;
88
}
9-
equals(isPositive, __, 'what is the value of isPositive?');
9+
equals(isPositive, true, 'what is the value of isPositive?');
1010
});
1111

1212
test("for", function() {
1313
var counter = 10;
1414
for (var i = 1; i <= 3; i++) {
1515
counter = counter + i;
1616
}
17-
equals(counter, __, 'what is the value of counter?');
17+
equals(counter, 16, 'what is the value of counter?');
1818
});
1919

2020
test("for in", function() {
@@ -26,17 +26,17 @@ test("for in", function() {
2626
var result = "";
2727
// for in enumerates the property names of an object
2828
for (property_name in person) {
29-
result = result + property_name;
29+
result = result + property_name;
3030
};
31-
equals(result, __, 'what is the value of result?');
31+
equals(result, "nameage", 'what is the value of result?');
3232
});
3333

3434
test("ternary operator", function() {
3535
var fruit = true ? "apple" : "orange";
36-
equals(fruit, __, 'what is the value of fruit?');
36+
equals(fruit, "apple", 'what is the value of fruit?');
3737

3838
fruit = false ? "apple" : "orange";
39-
equals(fruit, __, 'now what is the value of fruit?');
39+
equals(fruit, "orange", 'now what is the value of fruit?');
4040
});
4141

4242
test("switch", function() {
@@ -49,7 +49,7 @@ test("switch", function() {
4949
result = 2;
5050
break;
5151
}
52-
equals(result, __, 'what is the value of result?');
52+
equals(result, 2, 'what is the value of result?');
5353
});
5454

5555
test("switch default case", function() {
@@ -65,10 +65,10 @@ test("switch default case", function() {
6565
result = "Merry";
6666
break;
6767
}
68-
equals(result, __, 'what is the value of result?');
68+
equals(result, "Merry", 'what is the value of result?');
6969
});
7070

7171
test("null coallescion", function() {
7272
var result = null || "a value";
73-
equals(result, __, 'what is the value of result?');
73+
equals(result, "a value", 'what is the value of result?');
7474
});

topics/about_equality.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
module("About Equality (topics/about_equality.js)");
33

44
test("numeric equality", function() {
5-
equals(3 + __, 7, 'hmmmm?');
5+
equals(3 + 4, 7, 'hmmmm?');
66
});
77

88
test("string equality", function() {
9-
equals("3" + __, "37", "concatenate the strings");
9+
equals("3" + "7", "37", "concatenate the strings");
1010
});
1111

1212
test("equality without type coercion", function() {
13-
ok(3 === __, 'what is exactly equal to 3?');
13+
ok(3 === 3, 'what is exactly equal to 3?');
1414
});
1515

1616
test("equality with type coercion", function() {
17-
ok(3 == "__", 'what string is equal to 3, with type coercion?');
17+
ok(3 == "3", 'what string is equal to 3, with type coercion?');
1818
});
1919

2020
test("string literals", function() {
21-
equals("frankenstein", '__', "quote types are interchangable, but must match.");
21+
equals("frankenstein", 'frankenstein', "quote types are interchangable, but must match.");
2222
});

topics/about_functions_and_closure.js

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

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

2121
test("self invoking functions", function() {
@@ -24,22 +24,22 @@ test("self invoking functions", function() {
2424
// self invoking functions are used to provide scoping and to alias variables
2525
(function(pv) {
2626
var secretValue = "password";
27-
equals(pv, __, 'what is the value of pv?');
28-
equals(typeof(secretValue), "__", "is secretValue available in this context?");
29-
equals(typeof(publicValue), "__", "is publicValue available in this context?");
27+
equals(pv, "shared", 'what is the value of pv?');
28+
equals(typeof(secretValue), "string", "is secretValue available in this context?");
29+
equals(typeof(publicValue), "string", "is publicValue available in this context?");
3030
})(publicValue);
3131

32-
equals(typeof(secretValue), "__", "is secretValue available in this context?");
33-
equals(typeof(publicValue), "__", "is publicValue available in this context?");
32+
equals(typeof(secretValue), "undefined", "is secretValue available in this context?");
33+
equals(typeof(publicValue), "string", "is publicValue available in this context?");
3434
});
3535

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

4545
equals(add(1,2,3,4,5), 15, "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-
equals(result,__,"what will the value of invokee's this be?");
60+
equals(result,"I am this!Where did it come from?","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-
equals(result,__,"what will the value of invokee's this be?");
73+
equals(result,"I am this!I am arg1I am arg2","what will the value of invokee's this be?");
7474
});
7575

topics/about_numbers.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ module("About Numbers (topics/about_numbers.js)");
44
test("types", function() {
55
var typeOfIntegers = typeof(6);
66
var typeOfFloats = typeof(3.14159);
7-
equals(typeOfIntegers === typeOfFloats, __, 'are ints and floats the same type?');
8-
equals(typeOfIntegers, __, 'what is the javascript numeric type?');
9-
equals(1.0, __, 'what is a integer number equivalent to 1.0?');
7+
equals(typeOfIntegers === typeOfFloats, true, 'are ints and floats the same type?');
8+
equals(typeOfIntegers, "number", 'what is the javascript numeric type?');
9+
equals(1.0, 1, 'what is a integer number equivalent to 1.0?');
1010
});
1111

1212
test("NaN", function() {
1313
var resultOfFailedOperations = 7/'apple';
14-
equals(isNaN(resultOfFailedOperations), __, 'what will satisfy the equals assertion?');
15-
equals(resultOfFailedOperations == NaN, __, 'is NaN == NaN?');
14+
equals(isNaN(resultOfFailedOperations), true, 'what will satisfy the equals assertion?');
15+
equals(resultOfFailedOperations == NaN, false, 'is NaN == NaN?');
1616
});

topics/about_objects.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@ module("About Objects (topics/about_objects.js)");
33

44
test("object type", function() {
55
var empty_object = {};
6-
equals(typeof(empty_object), __, 'what is the type of an object?');
6+
equals(typeof(empty_object), "object", 'what is the type of an object?');
77
});
88

99
test("object literal notation", function() {
1010
var person = {
11-
__:__,
12-
__:__
11+
name: "Amory Blaine",
12+
age: 102
1313
};
1414
equals(person.name, "Amory Blaine", 'what is the person\'s name?');
1515
equals(person.age, 102, 'what is the person\'s age?');
1616
});
1717

1818
test("dynamically adding properties", function() {
1919
var person = {};
20-
person.__ = "Amory Blaine";
21-
person.__ = 102;
20+
person.name = "Amory Blaine";
21+
person.age = 102;
2222
equals(person.name, "Amory Blaine", 'what is the person\'s name?');
2323
equals(person.age, 102, 'what is the person\'s age?');
2424
});
2525

2626
test("adding properties from strings", function() {
2727
var person = {};
28-
person["__"] = "Amory Blaine";
29-
person["__"] = 102;
28+
person["name"] = "Amory Blaine";
29+
person["age"] = 102;
3030
equals(person.name, "Amory Blaine", 'what is the person\'s name?');
3131
equals(person.age, 102, 'what is the person\'s age?');
3232
});
@@ -36,7 +36,7 @@ test("adding functions", function() {
3636
name: "Amory Blaine",
3737
age: 102,
3838
toString: function() {
39-
return __; // HINT: use the 'this' keyword to refer to the person object.
39+
return "I " + this.name + " am " + this.age + " years old."; // HINT: use the 'this' keyword to refer to the person object.
4040
}
4141
};
4242
equals(person.toString(), "I Amory Blaine am 102 years old.", 'what should the toString function be?');

topics/about_operators.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ test("addition", function() {
77
for (var i = 0; i <= 5; i++) {
88
result = result + i;
99
}
10-
equals(result, __, "What is the value of result?");
10+
equals(result, 15, "What is the value of result?");
1111
});
1212

1313
test("assignment addition", function() {
@@ -16,23 +16,23 @@ test("assignment addition", function() {
1616
//the code below is just like saying result = result + i; but is more concise
1717
result += i;
1818
}
19-
equals(result, __, "What is the value of result?");
19+
equals(result, 15, "What is the value of result?");
2020
});
2121

2222
test("subtraction", function() {
2323
var result = 5;
2424
for (var i = 0; i <= 2; i++) {
2525
result = result - i;
2626
}
27-
equals(result, __, "What is the value of result?");
27+
equals(result, 2, "What is the value of result?");
2828
});
2929

3030
test("assignment subtraction", function() {
3131
var result = 5;
3232
for (var i = 0; i <= 2; i++) {
3333
result -= i;
3434
}
35-
equals(result, __, "What is the value of result?");
35+
equals(result, 2, "What is the value of result?");
3636
});
3737

3838
//Assignment operators are available for multiplication and division as well
@@ -43,5 +43,5 @@ test("modulus", function() {
4343
var x = 5;
4444
//again this is exactly the same as result = result % x
4545
result %= x;
46-
equals(result, __, "What is the value of result?");
46+
equals(result, 0, "What is the value of result?");
4747
});

topics/about_prototypal_inheritance.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Mammal.prototype = {
1616

1717
test("defining a 'class'", function() {
1818
var eric = new Mammal("Eric");
19-
equals(eric.sayHi(), __, 'what will Eric say?');
19+
equals(eric.sayHi(), 'Hello, my name is Eric', 'what will Eric say?');
2020
});
2121

2222
// add another function to the Mammal 'type' that uses the sayHi function
@@ -26,7 +26,7 @@ Mammal.prototype.favouriteSaying = function() {
2626

2727
test("more functions", function() {
2828
var bobby = new Mammal("Bobby");
29-
equals(bobby.favouriteSaying(), __, "what is Bobby's favourite saying?");
29+
equals(bobby.favouriteSaying(), "Bobby's favourite saying is Hello, my name is Bobby", "what is Bobby's favourite saying?");
3030
});
3131

3232
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
3535
return this.name.length;
3636
};
3737
// for the following statement asks the paul object to call a function that was added to the Mammal prototype after paul was constructed.
38-
equals(paul.numberOfLettersInName(), __, "how long is Paul's name?");
38+
equals(paul.numberOfLettersInName(), 4, "how long is Paul's name?");
3939
});
4040

4141
// helper function for inheritance.
@@ -55,6 +55,6 @@ extend(Bat, Mammal);
5555

5656
test("Inheritance", function() {
5757
var lenny = new Bat("Lenny", "1.5m");
58-
equals(lenny.sayHi(), __, "what does Lenny say?");
59-
equals(lenny.wingspan, __, "what is Lenny's wingspan?");
58+
equals(lenny.sayHi(), "Hello, my name is Lenny", "what does Lenny say?");
59+
equals(lenny.wingspan, "1.5m", "what is Lenny's wingspan?");
6060
});

0 commit comments

Comments
 (0)