Skip to content

Commit

Permalink
Added 5 tests to show operators. Includes modulus
Browse files Browse the repository at this point in the history
  • Loading branch information
caleywoods committed Apr 12, 2011
1 parent 177984b commit e5d7996
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions jskoans.htm
Expand Up @@ -7,6 +7,7 @@
<script type="text/javascript" src="support/qunit.js"></script>
<script type="text/javascript" src="support/koans.js"></script>
<script type="text/javascript" src="topics/about_asserts.js"></script>
<script type="text/javascript" src="topics/about_operators.js"></script>
<script type="text/javascript" src="topics/about_equality.js"></script>
<script type="text/javascript" src="topics/about_truthyness.js"></script>
<script type="text/javascript" src="topics/about_assignment.js"></script>
Expand Down
50 changes: 50 additions & 0 deletions topics/about_operators.js
@@ -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?");
});

});

0 comments on commit e5d7996

Please sign in to comment.