Add values on subsequent call in javascript function.?

Let’s consider I have the following function call,

function add(){
    x = 0;    
    return function(){        
        x+=1
            return function(){        
                return x+=1
            }
    };
}

add()()(); // output is 3

I am trying to make the above method in dynamic way, for example, If I add the multiple brackents those many time methods needs to called and it should give the final added value

function add(){
    x = 0 ;
    for(i = 0 i < ##; i++){ // need to run a loop four times
    x+=1
    }
}

add()()()();