Chunky Monkey - works but it doesn't

Tell us what’s happening:
Hello everyone!
This code is working if I put it into an html and test it in the browser, but it’s showing me “TypeError: cannot set property ‘counter’ of undefined”.

Could anyone tell my why is this?

Thank you in advance

Your code so far

    this.counter = size;
    console.log('counter is: ' + size);
  // initialize the final 2D arr
    var finalArr = [];
    //loop through it every 'counter' item
    for (var i = 0; i < arr.length; i+=counter) {
        console.log('i= ' + i); //just for me to check
        var sliceArr = arr.slice(i, size);
        size *=2;
        console.log('sliceArr= ' + sliceArr); //just for me to check 
    console.log(finalArr); //just for me to check
  return finalArr;

chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4);```
**Your browser information:**

Your Browser User Agent is: ```Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3230.0 Safari/537.36```.

**Link to the challenge:**

What does this.counter mean in this context?

Are you sure you want to use that?

I believe that fcc runs the challenges in strict mode under the hood; in strict mode, if this was not defined by the execution context, it remains undefined.

But it’s hard to tell just by looking at a partial code.

i wanted to create n’th variable called counter - so that the loop would iterate through the initial array every counter’th item

it’s not partial, it’s just missing the function declaration, this is how it was imported here

function chunkArrayInGroups(arr, size) {

Ok so the problem was with this.counter = i changed it to var counter = and it’s all good.

Thank you!

1 Like