forked from liammclennan/JavaScript-Koans
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added 5 tests to show operators. Includes modulus
- Loading branch information
1 parent
177984b
commit e5d7996
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
$(document).ready(function(){ | ||
|
||
module("About Operators (topics/about_operators.js)"); | ||
|
||
test("addition", function() { | ||
var result = 0; | ||
//starting i at 0, add i to result and increment i by 1 until i is equal to 5 | ||
for (var i = 0; i <= 5; i++) { | ||
result = result + i; | ||
} | ||
equals(result, __, "What is the value of result?"); | ||
}); | ||
|
||
test("assignment addition", function() { | ||
var result = 0; | ||
for (var i = 0; i <=5; i++) { | ||
//the code below is just like saying result = result + i; but is more concise | ||
result += i; | ||
} | ||
equals(result, __, "What is the value of result?"); | ||
}); | ||
|
||
test("subtraction", function() { | ||
var result = 5; | ||
for (var i = 0; i <= 2; i++) { | ||
result = result - i; | ||
} | ||
equals(result, __, "What is the value of result?"); | ||
}); | ||
|
||
test("assignment subtraction", function() { | ||
var result = 5; | ||
for (var i = 0; i <= 2; i++) { | ||
result -= i; | ||
} | ||
equals(result, __, "What is the value of result?"); | ||
}); | ||
|
||
//Assignment operators are available for multiplication and division as well | ||
//let's do one more, the modulo operator, used for showing division remainder | ||
|
||
test("modulus", function() { | ||
var result = 10; | ||
var x = 5; | ||
//again this is exactly the same as result = result % x | ||
result %= x; | ||
equals(result, __, "What is the value of result?"); | ||
}); | ||
|
||
}); |