From e5d799689565370b6fa9854205afd9c34e66d857 Mon Sep 17 00:00:00 2001 From: Caley Woods Date: Tue, 12 Apr 2011 08:37:24 -0500 Subject: [PATCH] Added 5 tests to show operators. Includes modulus --- jskoans.htm | 1 + topics/about_operators.js | 50 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 topics/about_operators.js diff --git a/jskoans.htm b/jskoans.htm index 43296404..1700e095 100644 --- a/jskoans.htm +++ b/jskoans.htm @@ -7,6 +7,7 @@ + diff --git a/topics/about_operators.js b/topics/about_operators.js new file mode 100644 index 00000000..4113d7cc --- /dev/null +++ b/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?"); + }); + +});