Chunky Monkey: Correct answer but incorrect format

Tell us what’s happening:

I can get the proper results as an array, but the formatting is incorrect and the answer is marked wrong. I had this happen in another array challenge too. If someone can point me as to what I’m messing up, it will probably fix both issues.

Thank you!

Your code so far
var all = [];
var stor = [];

function chunkArrayInGroups(arr, size) {

for (var i = 0; i < arr.length; i = i + size) {
stor = arr.slice(i,size + i);
stor = [];
return all;

//chunkArrayInGroups([“a”, “b”, “c”, “d”], 2);
//chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3);
//chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2)
chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 2);

**Your browser information:**

Your Browser User Agent is: ```Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0```.

**Link to the challenge:**

I’m not sure about the formatting, but I see this error: ReferenceError: all is not defined

I’m confused how it returns something then…

edit: when it copied over it excluded the first line

Your code does work for a single test. The problem is your use of the global all. Since the FCC tests run consecutively, the all array does not get set back to a blank array each time a new test is ran, so at the start of each call to the function, all still has the value it had at the end of the function. Move it inside the function and all is good (pun intended).

1 Like

Awesome! Thank you very much!