I have this:
$(document).ready(function() {
$('input[type="button"]').click(function() {
var sum = 0, count = 0, result;
$('input[type="text"]').each(function() {
var val = Number( $(this).val() );
if (val && val >= 0) {
sum += Number(val);
count++;
}
});
the error is that it does not take zero into account,
for example, 10 and 0 should average out to 5, not 10.
result = (count > 0) ? sum/count : 'no values found';
$('#result').html( result );
});
});
How can I make it account for the number 0 when it figures out averages?