Skip to content

Commit

Permalink
Add in basic multiply functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
darrencauthon committed Dec 28, 2011
1 parent 66cd011 commit b2e0c41
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mathstuff.js
Expand Up @@ -8,4 +8,13 @@
});
return value;
};

$.fn.multiply = function(){
if (this.length == 0) return 0;
var value = 1;
this.each(function(){
value = value * $(this).val();
});
return value;
};
})( jQuery );
20 changes: 20 additions & 0 deletions mathstuff.tests.html
Expand Up @@ -62,6 +62,26 @@
var value = $('.two').sum();
equal(value, 1.3, "should return 1.3");
});

module("Multiply");

test("returns 0 when given no items", function(){
var value = $('input[name=nothing]').multiply();
equal(value, 0, "should return zero" );
});

test("returns 1 when given one item of value 1", function(){
$('input[name=one]').val(1);
var value = $('input[name=one]').multiply();
equal(value, 1, "should return one" );
});

test("returns 6 when given two items that multiply to 6", function(){
$('#B1').val(2);
$('#B2').val(3);
var value = $('.two').multiply();
equal(value, 6, "should return six" );
});
});
</script>

Expand Down

0 comments on commit b2e0c41

Please sign in to comment.