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?

Move count out of the if(val

        $('input[type="text"]').each(function() {
            var val = Number( $(this).val() );
            if (val && val >= 0) {
                sum += Number(val);
            }
            count++;
        });
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.