Q:

Javascript loop for estructure

i have to solve the following function: "x" represent a number of cycles. One cycle sums +1 and then multiply the result *2. For example:
0 cycles = 0 + 1 = 1 (result)
1 cycles = 1 * 2 = 2 (result)
2 cycles = 2 + 1 = 3 (result)
3 cycles = 3 * 2 = 6 (result)
4 cycles = 6 + 1 = 7 (result) and so on.

I have this function:
function final(x) {
    for (var i = 0; i < x; i++) {
        var result = x[i] * 2 + 1
    }
    return result;
}

Can you help me out?

A:

Thanks for your help, the solution finally was this: 
function final(x){
var result = 0;
for (var i = 0; i < x; i++){
if (i % 2 === 0){
result = result * 2 + 1;}
else{
result = (result + 1);}
}
return result+1;
}

