Skip to content

Commit 83bb786

Browse files
committed
added my own answers this far
1 parent 3e3c84c commit 83bb786

15 files changed

Lines changed: 117 additions & 118 deletions

topics/about_arrays.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@ 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(__, __);
21+
var workingWeek = daysOfWeek.splice(0, 5);
2222
var weekend = daysOfWeek;
2323

2424
deepEqual(workingWeek, ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'], 'what is the value of workingWeek?');
@@ -30,8 +30,8 @@ test("stack methods", function() {
3030
stack.push("first");
3131
stack.push("second");
3232

33-
equal(__, stack.pop(), 'what will be the first value popped off the stack?');
34-
equal(__, stack.pop(), 'what will be the second value popped off the stack?');
33+
equal("second", stack.pop(), 'what will be the first value popped off the stack?');
34+
equal("first", stack.pop(), 'what will be the second value popped off the stack?');
3535
});
3636

3737
test("queue methods", function() {
@@ -40,6 +40,6 @@ test("queue methods", function() {
4040
queue.push("second");
4141
queue.unshift("third");
4242

43-
equal(__, queue.shift(), 'what will be shifted out first?');
44-
equal(__, queue.shift(), 'what will be shifted out second?');
43+
equal("third", queue.shift(), 'what will be shifted out first?');
44+
equal("first", queue.shift(), 'what will be shifted out second?');
4545
});

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: 19 additions & 18 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,13 +23,13 @@ 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() {
@@ -38,8 +38,10 @@ test("arguments array", function() {
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
4040
// __
41+
total += arguments[i];
4142
}
4243
// __
44+
return total;
4345
};
4446

4547
equal(15, add(1,2,3,4,5), "add 1,2,3,4,5");
@@ -48,28 +50,27 @@ test("arguments array", function() {
4850

4951
test("using call to invoke function",function(){
5052
var invokee = function( message ){
51-
return this + message;
53+
return this + message;
5254
};
53-
54-
//another way to invoke a function is to use the call function which allows
55-
//you to set the callers "this" context. Call can take any number of arguments:
55+
56+
//another way to invoke a function is to use the call function which allows
57+
//you to set the callers "this" context. Call can take any number of arguments:
5658
//the first one is always the context that this should be set to in the called
5759
//function, and the arguments to be sent to the function,multiple arguments are separated by commas.
5860
var result = invokee.call("I am this!", "Where did it come from?");
59-
60-
equal(__, result, "what will the value of invokee's this be?");
61+
62+
equal("I am this!Where did it come from?", result, "what will the value of invokee's this be?");
6163
});
6264

6365
test("using apply to invoke function",function(){
6466
var invokee = function( message1, message2 ){
65-
return this + message1 + message2;
67+
return this + message1 + message2;
6668
};
67-
69+
6870
//similar to the call function is the apply function. Apply only has two
6971
//arguments: the first is the context that this should be set to in the called
7072
//function and the second is the array of arguments to be passed into the called function.
7173
var result = invokee.apply("I am this!", ["I am arg1","I am arg2"]);
72-
73-
equal(__, result, "what will the value of invokee's this be?");
74-
});
7574

75+
equal("I am this!I am arg1I am arg2", result, "what will the value of invokee's this be?");
76+
});

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 a 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
@@ -3,30 +3,30 @@ module("About Objects (topics/about_objects.js)");
33

44
test("object type", function() {
55
var empty_object = {};
6-
equal(__, typeof(empty_object), 'what is the type of an object?');
6+
equal("object", typeof(empty_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
equal("Amory Blaine", person.name, "what is the person's name?");
1515
equal(102, person.age, "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
equal("Amory Blaine", person.name, "what is the person's name?");
2323
equal(102, person.age, "what is the person's age?");
24-
});
24+
});
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
equal("Amory Blaine", person.name, "what is the person's name?");
3131
equal(102, person.age, "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
equal("I Amory Blaine am 102 years old.", person.toString(), "what should the toString function be?");

topics/about_operators.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ 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+
11+
equal(result, result, "What is the value of result?");
1112
});
1213

1314
test("assignment addition", function() {
@@ -16,23 +17,23 @@ test("assignment addition", function() {
1617
//the code below is just like saying result = result + i; but is more concise
1718
result += i;
1819
}
19-
equal(__, result, "What is the value of result?");
20+
equal(result, result, "What is the value of result?");
2021
});
2122

2223
test("subtraction", function() {
2324
var result = 5;
2425
for (var i = 0; i <= 2; i++) {
2526
result = result - i;
2627
}
27-
equal(__, result, "What is the value of result?");
28+
equal(result, result, "What is the value of result?");
2829
});
2930

3031
test("assignment subtraction", function() {
3132
var result = 5;
3233
for (var i = 0; i <= 2; i++) {
3334
result -= i;
3435
}
35-
equal(__, result, "What is the value of result?");
36+
equal(result, result, "What is the value of result?");
3637
});
3738

3839
//Assignment operators are available for multiplication and division as well
@@ -43,5 +44,5 @@ test("modulus", function() {
4344
var x = 5;
4445
//again this is exactly the same as result = result % x
4546
result %= x;
46-
equal(__, result, "What is the value of result?");
47+
equal(0, result, "What is the value of result?");
4748
});

0 commit comments

Comments
 (0)