Does the FCC console works different than chrome console? [SOLVED]

Hi,
Im on the Sum All Odd Fibonacci Numbers challange and as I go I like to test stuff out step by step. So I know this is not the final solution but i was wondering why this while loop works in the chrome console but not in the fcc console.

I have this code in the fcc console:

function sumFibs(num) {
  
  var a = 0;
  var b = 1;
  var c;
  var arr = [];
  
  while(c < num) {
    c = a + b;
    arr.push(c);
    a = b;
    b = c;
  }

  
  return arr;
}

sumFibs(100);

This returns an empty array while in the chrome console I get an array filled with numbers

Thanks a lot

So FCC doesn’t really have a console. It has a code editor and an output display. The output display only shows the last returned value.

I’m not entirely sure what you mean when you say “while in the chrome console I get an array filled with numbers”. Below is a screenshot of the chrome console with the above code pasted in:

For an online editor with a console, I recommend repl.it, which has the added benefit of being embed-able here on the forum, like so:

As for why your function returns an empty array, it’s because the variable c is never initialized and is therefor undefined. (Sidebar: please don’t name your variables things like a, b, and c. I know it’s faster when you’re working, but at least change them to something meaningful before asking someone to read your code.)

2 Likes

Thank you! I thought that by just calling var c; it would be enough to initialize it, but if i set it to 0 it works.