Skip to content

Commit a7659e8

Browse files
author
Em01
committed
Additional
1 parent 71394f4 commit a7659e8

3 files changed

Lines changed: 76 additions & 76 deletions

File tree

topics/about_control_structures.js

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,73 @@
1-
// module("About Control Structures (topics/about_control_structures.js)");
1+
module("About Control Structures (topics/about_control_structures.js)");
22

3-
// test("if", function() {
4-
// var isPositive = false;
5-
// if (2 > 0) {
6-
// isPositive = true;
7-
// }
8-
// equal(true, isPositive, 'what is the value of isPositive?');
9-
// });
3+
test("if", function() {
4+
var isPositive = false;
5+
if (2 > 0) {
6+
isPositive = true;
7+
}
8+
equal(true, isPositive, 'what is the value of isPositive?');
9+
});
1010

11-
// test("for", function() {
12-
// var counter = 10;
13-
// for (var i = 1; i <= 3; i++) {
14-
// counter = counter + i;
15-
// }
16-
// equal(__, counter, 'what is the value of counter?');
17-
// });
11+
test("for", function() {
12+
var counter = 10;
13+
for (var i = 1; i <= 3; i++) {
14+
counter = counter + i;
15+
}
16+
equal(16, counter, 'what is the value of counter?');
17+
});
1818

19-
// test("for in", function() {
20-
// // this syntax will be explained in about objects
21-
// var person = {
22-
// name: "Amory Blaine",
23-
// age: 102
24-
// };
25-
// var result = "";
26-
// // for in enumerates the property names of an object
27-
// for (var property_name in person) {
28-
// result = result + property_name;
29-
// }
30-
// equal(__, result, 'what is the value of result?');
31-
// });
19+
test("for in", function() {
20+
// this syntax will be explained in about objects
21+
var person = {
22+
name: "Amory Blaine",
23+
age: 102
24+
};
25+
var result = "";
26+
// for in enumerates the property names of an object
27+
for (var property_name in person) {
28+
result = result + property_name;
29+
}
30+
equal("nameage", result, 'what is the value of result?');
31+
});
3232

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

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

41-
// test("switch", function() {
42-
// var result = 0;
43-
// switch (2) {
44-
// case 1:
45-
// result = 1;
46-
// break;
47-
// case 1+1:
48-
// result = 2;
49-
// break;
50-
// }
51-
// equal(__, result, 'what is the value of result?');
52-
// });
41+
test("switch", function() {
42+
var result = 0;
43+
switch (2) {
44+
case 1:
45+
result = 1;
46+
break;
47+
case 1+1:
48+
result = 2;
49+
break;
50+
}
51+
equal(2, result, 'what is the value of result?');
52+
});
5353

54-
// test("switch default case", function() {
55-
// var result = "Pippin";
56-
// switch ("m") {
57-
// case "f":
58-
// result = "Frodo";
59-
// break;
60-
// case "s":
61-
// result = "Samwise";
62-
// break;
63-
// default:
64-
// result = "Merry";
65-
// break;
66-
// }
67-
// equal(__, result, 'what is the value of result?');
68-
// });
54+
test("switch default case", function() {
55+
var result = "Pippin";
56+
switch ("m") {
57+
case "f":
58+
result = "Frodo";
59+
break;
60+
case "s":
61+
result = "Samwise";
62+
break;
63+
default:
64+
result = "Merry";
65+
break;
66+
}
67+
equal("Merry", result, 'what is the value of result?');
68+
});
6969

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

topics/about_prototypal_inheritance.js

Lines changed: 3 additions & 3 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.

topics/about_prototype_chain.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,37 @@ child.b = 2;
2727
* */
2828

2929
test("Is there an 'a' and 'b' own property on child?", function () {
30-
equal(__, child.hasOwnProperty('a'), 'child.hasOwnProperty(\'a\')?');
31-
equal(__, child.hasOwnProperty('b'), 'child.hasOwnProperty(\'b\')?');
30+
equal(true, child.hasOwnProperty('a'), 'child.hasOwnProperty(\'a\')?');
31+
equal(true, child.hasOwnProperty('b'), 'child.hasOwnProperty(\'b\')?');
3232
});
3333

3434
test("Is there an 'a' and 'b' property on child?", function () {
35-
equal(__, child.a, 'what is \'a\' value?');
36-
equal(__, child.b, 'what is \'b\' value?');
35+
equal(1, child.a, 'what is \'a\' value?');
36+
equal(2, child.b, 'what is \'b\' value?');
3737
});
3838

3939
test("If 'b' was removed, whats b value?", function () {
4040
delete child.b;
41-
equal(__, child.b, 'what is \'b\' value now?');
41+
equal(3, child.b, 'what is \'b\' value now?');
4242
});
4343

4444

4545
test("Is there a 'c' own property on child?", function () {
46-
equal(__, child.hasOwnProperty('c'), 'child.hasOwnProperty(\'c\')?');
46+
equal(false, child.hasOwnProperty('c'), 'child.hasOwnProperty(\'c\')?');
4747
});
4848

4949
// Is there a 'c' own property on child? No, check its prototype
5050
// Is there a 'c' own property on child.[[Prototype]]? Yes, its value is...
5151
test("Is there a 'c' property on child?", function () {
52-
equal(__, child.c, 'what is the value of child.c?');
52+
equal(4, child.c, 'what is the value of child.c?');
5353
});
5454

5555

5656
// Is there a 'd' own property on child? No, check its prototype
5757
// Is there a 'd' own property on child.[[Prototype]]? No, check it prototype
5858
// child.[[Prototype]].[[Prototype]] is null, stop searching, no property found, return...
5959
test("Is there an 'd' property on child?", function () {
60-
equal(__, child.d, 'what is the value of child.d?');
60+
equal(undefined, child.d, 'what is the value of child.d?');
6161
});
6262

6363

0 commit comments

Comments
 (0)