Skip to content

Commit ef631fe

Browse files
author
Afshin Mokhtari
committed
first dive into koans
1 parent ec4a522 commit ef631fe

File tree

10 files changed

+49
-48
lines changed

10 files changed

+49
-48
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.swp
2-
.idea
2+
.idea
3+
.DS*

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_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: 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-
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?");
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
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: 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_strings.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,31 @@ module("About Strings (topics/about_strings.js)");
44
test("delimiters", function() {
55
var singleQuotedString = 'apple';
66
var doubleQuotedString = "apple";
7-
equal(__, singleQuotedString === doubleQuotedString, 'are the two strings equal?');
7+
equal(true, singleQuotedString === doubleQuotedString, 'are the two strings equal?');
88
});
99

1010
test("concatenation", function() {
1111
var fruit = "apple";
1212
var dish = "pie";
13-
equal(__, fruit + " " + dish, 'what is the value of fruit + " " + dish?');
13+
equal('apple pie', fruit + " " + dish, 'what is the value of fruit + " " + dish?');
1414
});
1515

1616
test("character Type", function() {
1717
var characterType = typeof("Amory".charAt(1)); // typeof will be explained in about reflection
18-
equal(__, characterType, 'Javascript has no character type');
18+
equal("string", characterType, 'Javascript has no character type');
1919
});
2020

2121
test("escape character", function() {
2222
var stringWithAnEscapedCharacter = "\u0041pple";
23-
equal(__, stringWithAnEscapedCharacter, 'what is the value of stringWithAnEscapedCharacter?');
23+
equal("\u0041pple", stringWithAnEscapedCharacter, 'what is the value of stringWithAnEscapedCharacter?');
2424
});
2525

2626
test("string.length", function() {
2727
var fruit = "apple";
28-
equal(__, fruit.length, 'what is the value of fruit.length?');
28+
equal(5, fruit.length, 'what is the value of fruit.length?');
2929
});
3030

3131
test("slice", function() {
3232
var fruit = "apple pie";
33-
equal(__, fruit.slice(0,5), 'what is the value of fruit.slice(0,5)?');
33+
equal('apple', fruit.slice(0,5), 'what is the value of fruit.slice(0,5)?');
3434
});

topics/about_truthyness.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ module("About Truthyness (topics/about_truthyness.js)");
33

44
test("truthyness of positive numbers", function() {
55
var oneIsTruthy = 1 ? true : false;
6-
equal(__, oneIsTruthy, 'is one truthy?');
6+
equal(true, oneIsTruthy, 'is one truthy?');
77
});
88

99
test("truthyness of negative numbers", function() {
1010
var negativeOneIsTruthy = -1 ? true : false;
11-
equal(__, negativeOneIsTruthy, 'is -1 truthy?');
11+
equal(true, negativeOneIsTruthy, 'is -1 truthy?');
1212
});
1313

1414
test("truthyness of zero", function() {
1515
var zeroIsTruthy = 0 ? true : false;
16-
equal(__, zeroIsTruthy, 'is 0 truthy?');
16+
equal(false, zeroIsTruthy, 'is 0 truthy?');
1717
});
1818

1919
test("truthyness of null", function() {
2020
var nullIsTruthy = null ? true : false;
21-
equal(__, nullIsTruthy, 'is null truthy?');
21+
equal(false, nullIsTruthy, 'is null truthy?');
2222
});

0 commit comments

Comments
 (0)