Edit in JSFiddle

//Question
//g()()()('al');
//output goooal
//g()()()()()('al');
//output goooooal


var rtn = g()()()()('al');
console.log(rtn); //gooooal

var rtn2 = g()()()()()()()('al');
console.log(rtn2); //goooooooal

function g(word) {
    
    if(word) {
        word += 'o';
    } else {
        word = 'go';
    }
        
    return (function(tail) {
        
        if(tail){
            word += tail;
            return word;
        } else {
           return g(word);
        }
    });
}