Basic Recursive Loop

by joshpauljohnson

HTML

<article></article>

JavaScript

var recursiveLoop = function(start, max, total) {
    if (start >= max) {
        return total;
    } else {
        start++;
        total += start;
        return recursiveLoop(start, max, total);
    }
        
};

$("article").text( recursiveLoop(0, 5, 0) );