Skip to content

Commit 465dfe1

Browse files
committed
All tests passing
1 parent 2ba675d commit 465dfe1

17 files changed

+114
-113
lines changed

topics/about_arrays.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,35 @@ module("About Arrays (topics/about_arrays.js)");
22

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

1010
test("array type", function() {
11-
equal(__, typeof([]), 'what is the type of an array?');
11+
equal('object', typeof([]), 'what is the type of an array?');
1212
});
1313

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

1919
test("splice", function() {
2020
var daysOfWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
21-
var workingWeek = daysOfWeek.splice(__, __);
22-
ok(workingWeek.equalTo([__]), 'what is the value of workingWeek?');
23-
ok(daysOfWeek.equalTo([__]), 'what is the value of daysOfWeek?');
21+
ok(daysOfWeek.equalTo(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']), '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+
2425
});
2526

2627
test("stack methods", function() {
2728
var stack = [];
2829
stack.push("first");
2930
stack.push("second");
3031

31-
equal(__, stack.pop(), 'what will be the first value popped off the stack?');
32-
equal(__, stack.pop(), 'what will be the second value popped off the stack?');
32+
equal('second', stack.pop(), 'what will be the first value popped off the stack?');
33+
equal('first', stack.pop(), 'what will be the second value popped off the stack?');
3334
});
3435

3536
test("queue methods", function() {
@@ -38,6 +39,6 @@ test("queue methods", function() {
3839
queue.push("second");
3940
queue.unshift("third");
4041

41-
equal(__, queue.shift(), 'what will be shifted out first?');
42-
equal(__, queue.shift(), 'what will be shifted out second?');
42+
equal('third', queue.shift(), 'what will be shifted out first?');
43+
equal('first', queue.shift(), 'what will be shifted out second?');
4344
});

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(__ === true, 'what will satisfy the ok assertion?');
5+
ok(true === true, 'what will satisfy the ok assertion?');
66
});
77

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

1212
test("equal", function() {
13-
equal(__, 1 + 1, 'what will satisfy the equal assertion?');
13+
equal( 2, 1 + 1, 'what will satisfy the equal 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
equal(temp, 1, "Assign a value to the variable temp");
77
});
88

99
test("global variables", function() {
1010
temp = 1; // Not using var is an example. Always use var in practise.
11-
equal(window.__, temp, 'global variables are assigned to the window object');
11+
equal(window.temp, temp, 'global variables are assigned to the window object');
1212
});

topics/about_control_structures.js

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

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

1919
test("for in", function() {
@@ -27,15 +27,15 @@ test("for in", function() {
2727
for (var property_name in person) {
2828
result = result + property_name;
2929
};
30-
equal(__, result, 'what is the value of result?');
30+
equal("nameage", result, 'what is the value of result?');
3131
});
3232

3333
test("ternary operator", function() {
3434
var fruit = true ? "apple" : "orange";
35-
equal(__, fruit, 'what is the value of fruit?');
35+
equal("apple", fruit, 'what is the value of fruit?');
3636

3737
fruit = false ? "apple" : "orange";
38-
equal(__, fruit, 'now what is the value of fruit?');
38+
equal("orange", fruit, 'now what is the value of fruit?');
3939
});
4040

4141
test("switch", function() {
@@ -48,7 +48,7 @@ test("switch", function() {
4848
result = 2;
4949
break;
5050
}
51-
equal(__, result, 'what is the value of result?');
51+
equal(2, result, 'what is the value of result?');
5252
});
5353

5454
test("switch default case", function() {
@@ -64,10 +64,10 @@ test("switch default case", function() {
6464
result = "Merry";
6565
break;
6666
}
67-
equal(__, result, 'what is the value of result?');
67+
equal("Merry", result, 'what is the value of result?');
6868
});
6969

7070
test("null coalescing", function() {
7171
var result = null || "a value";
72-
equal(__, result, 'what is the value of result?');
72+
equal("a value", result, 'what is the value of result?');
7373
});

topics/about_equality.js

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

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

88
test("string equality", function() {
9-
equal("3" + __, "37", "concatenate the strings");
9+
equal("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-
equal(__, "frankenstein", "quote types are interchangable, but must match.");
22-
equal(__, 'frankenstein', "quote types can use both single and double quotes.");
21+
equal('frankenstein', "frankenstein", "quote types are interchangable, but must match.");
22+
equal("frankenstein", 'frankenstein', "quote types can use both single and double quotes.");
2323
});

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_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-
equal(__, typeOfIntegers === typeOfFloats, 'are ints and floats the same type?');
8-
equal(__, typeOfIntegers, 'what is the javascript numeric type?');
9-
equal(__, 1.0, 'what is a integer number equivalent to 1.0?');
7+
equal(true, typeOfIntegers === typeOfFloats, 'are ints and floats the same type?');
8+
equal('number', typeOfIntegers, 'what is the javascript numeric type?');
9+
equal(1, 1.0, 'what is an integer number equivalent to 1.0?');
1010
});
1111

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

topics/about_objects.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
21
module("About Objects (topics/about_objects.js)");
32

43
test("object type", function() {
54
var empty_object = {};
6-
equal(__, typeof(empty_object), 'what is the type of an object?');
5+
equal('object', typeof(empty_object), 'what is the type of an object?');
76
});
87

98
test("object literal notation", function() {
109
var person = {
11-
__:__,
12-
__:__
10+
name:'Amory Blaine',
11+
age: 102
1312
};
1413
equal("Amory Blaine", person.name, "what is the person's name?");
1514
equal(102, person.age, "what is the person's age?");
1615
});
1716

1817
test("dynamically adding properties", function() {
1918
var person = {};
20-
person.__ = "Amory Blaine";
21-
person.__ = 102;
19+
person.name = "Amory Blaine";
20+
person.age = 102;
2221
equal("Amory Blaine", person.name, "what is the person's name?");
2322
equal(102, person.age, "what is the person's age?");
2423
});
2524

2625
test("adding properties from strings", function() {
2726
var person = {};
28-
person["__"] = "Amory Blaine";
29-
person["__"] = 102;
27+
person["name"] = "Amory Blaine";
28+
person["age"] = 102;
3029
equal("Amory Blaine", person.name, "what is the person's name?");
3130
equal(102, person.age, "what is the person's age?");
3231
});
@@ -36,7 +35,8 @@ test("adding functions", function() {
3635
name: "Amory Blaine",
3736
age: 102,
3837
toString: function() {
39-
return __; // HINT: use the 'this' keyword to refer to the person object.
38+
var me = "I " + this.name + " am " + this.age + " years old."
39+
return me; // HINT: use the 'this' keyword to refer to the person object.
4040
}
4141
};
4242
equal("I Amory Blaine am 102 years old.", person.toString(), "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-
equal(__, result, "What is the value of result?");
10+
equal(15, result, "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-
equal(__, result, "What is the value of result?");
19+
equal(15, result, "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-
equal(__, result, "What is the value of result?");
27+
equal(2, result, "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-
equal(__, result, "What is the value of result?");
35+
equal(2, result, "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-
equal(__, result, "What is the value of result?");
46+
equal(0, result, "What is the value of result?");
4747
});

topics/about_prototypal_inheritance.js

Lines changed: 6 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-
equal(__, eric.sayHi(), 'what will Eric say?');
19+
equal('Hello, my name is Eric', eric.sayHi(), '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-
equal(__, bobby.favouriteSaying(), "what is Bobby's favourite saying?");
29+
equal('Bobby\'s favourite saying is Hello, my name is Bobby', bobby.favouriteSaying(), "what is Bobby's favourite saying?");
3030
});
3131

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

4242
// helper function for inheritance.
@@ -56,6 +56,7 @@ extend(Bat, Mammal);
5656

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

0 commit comments

Comments
 (0)