Total=0

Hi,
Im getting and error in firefox saying that total is not defined, However
i think it is in blue. i understand the return statement concept just not how it works in conjuction with arrays.

any help?

function sum(numbers)
{
if (numbers.length ==0) return 0;
for ( var i=0, total=0;i <numbers.length; i++)
total+= numbers[i];

		return total;
		}
		
		document.getElementById("txtTotal").value = total;

It is correcting in saying that, when you use a var inside a function it becomes part of the local scope which is the function itself. If you declare the var outside the function it becomes part of the global scope so everything can use it.

Basically you just need to update it so it looks like

var total = 0;

function sum(numbers) {
    if (!numbers.length) return 0;
    
    for (var i = 0; i < numbers.length; i++) {
        total += numbers[i];
    }
    
    return total;
}

document.getElementById("txtTotal").value = total;