0

EDIT: Turns out I had filtering enabled which removed the console.log outputs from Chrome's console. I disabled it and my issue was fixed.

I have very basic experience with JS and am attempting to translate my Java code into JS. The issue I'm having is that when running my code within Chrome's console, I am being returned "undefined". However, when running on online compilers such as codepad.remoteinterview.io or JSBin.com, their consoles are printing what I need it to. Is this a problem on my end, whether or not so, is there a way I can fix this? Thank you.

function writeOut(i) {
    if (i !== 0)
        return "(1 / " + i + ") + "+writeOut(i-1);
    else // base case
        return "";
}

function sum(i) {
    if (i === 1) // base case
        return 1;
    else
        return  1 / i + sum(i - 1);
}


for (var i = 1; i <= 10; i++) {
    console.log("(1 / " + i + "): " + (writeOut(i)) + "| Sum: " + sum(i));
}
Infinity
  • 31
  • 1
  • 6
  • 1
    [Looks fine to me](https://i.imgur.com/MJVwa82.png) or maybe I didn't understand how you test or what you expect to see ? – Denys Séguret Aug 25 '17 at 08:23
  • When you directly run the function from console, it will return `undefined` because it doesn't have a return value. When you run on online ide's the return value won't shown in console. – Sagar V Aug 25 '17 at 08:27
  • @DenysSéguret I thought something was wrong with my code when I ran it because I was only returned "undefined" on Chrome's console. Turns out I had filtering on... I have no idea when or why I enabled it in the first place. Thanks for the reply! – Infinity Aug 25 '17 at 17:53
  • @i-- Thats really good to know, thank you – Infinity Aug 25 '17 at 17:54

0 Answers0