Chunky Monkey - code works on REPL.it, not on freecodecamp. Why?

Chunky Monkey - code works on REPL.it, not on freecodecamp. Why?
0.0 0

#1

Tell us what’s happening:
I think that I have written a possible solution, which works when I run the code on repl.it, but whenever I try it on the freecodecamp site, it doesn’t work. I have been reviewing the code over and over, but I cannot seem to find the problem. Any ideas? Thanks!

Your code so far

function chunkArrayInGroups(arr, size) {
  var twoDimArray = [];
  var times = arr.length / size;
  var pointer1 = 0;
  var pointer2 = size;
  for (i = times; i > 0; i--) {
    var tempArr = arr.slice(pointer1, pointer2);
    twoDimArray.push(tempArr);
    pointer1 += size;
    pointer2 += size;
  } console.log(twoDimArray);
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);

Your browser information:

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

Link to the challenge:


#2

Your function creates an array called twoDimArray and you display it to the console using a console.log statement, but the array needs to be returned to the calling function.


#3

That works. Thanks! So should I never use console.log in freecodecamp when I expect some output? Is the output area not the equivalent of the console?


#4

console.log is typically used for debugging purposes, so you can see the value of something or check that a certain part of your code is executing in an expected way. console.log displays to the browser’s console (Ctrl+Shft+J in Chrome). When you need to return a value from a function, you must use the return statement. Not all functions require a returned value, because some just perform certain tasks.


#5

The black output area is more of a “fake console”. It is very limited in what it can show. It is strictly something FCC created to simulate the browser’s console, but it typically only shows the last console.log statement (if it does at all). Always use the browser’s console to really know what is being displayed to the console.