# Nested Loops - What am I doing wrong?j

What am I doing wrong?

Instructions:

1. Construct a nested for loop that increments the counter variable.
2. Construct your second for loop below (hint: use the innerLength element as the inner loop’s condition).
3. Inside of your nested for loop increment the counter on every iteration.

My code so far:

``````const outer = [1, 2, 3];
let counter = 0;

for (let i = 0; i < outer.length; i++) {
let innerLength = outer[i];
for (let j = 0; j < innerLength.length; j++) {
counter = innerLength[i];
}
}
console.log(counter);
``````

The code block logs into the console: 0. It’s supposed to log 6. What am I doing wrong?

Hi!
Instruction 2 says to use innerLength for your inner loop - you just want the variable, not its length.
Instruction 3 says to increment counter. i.e. just add one to itself.

Just a couple of tweaks and you should be sorted.

const outer = [1, 2, 3];
let counter = 0;

for (let i = 0; i < outer.length; i += 1) {
let innerLength = outer[i];

for(let j = 0; j < innerLength; j++){
counter +=1

}

}
console.log(counter);

// Should print the number 6