JavaScript: function returning NAN
        Posted  
        
            by 
                Michael
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Michael
        
        
        
        Published on 2012-08-27T21:37:17Z
        Indexed on 
            2012/08/27
            21:38 UTC
        
        
        Read the original article
        Hit count: 271
        
JavaScript
I'm working on a codecademy.com lesson with instructions to write the calculateTotal function below. When I click run, it's returning NaN. Anyone know what's wrong with the calculateTotal function as I wrote it that's making it return NaN. Note, I understand that NaN means not a number...
// runner times
var carlos = [9.6,10.6,11.2,10.3,11.5];
var liu = [10.6,11.2,9.4,12.3,10.1];
var timothy = [12.2,11.8,12.5,10.9,11.1];
// declare your function calculateTotal here
var calculateTotal = function(raceTimes){
    var totalTime; 
    for(i = 0; i < raceTimes.length; i++){
        totalTime += raceTimes[i]; 
        return totalTime; 
    }
};
var liuTotal = calculateTotal(liu);
console.log(liuTotal);
© Stack Overflow or respective owner