Roman Numerals Problem

After a day of pondering I finally got my roman numeral converter to work. The problem though is when I put it in FCC editor and compile it, it doesn’t run. It runs on jsbin though.
mycode. Help me please thanks.

Did you remove console.log() around the call to convertToRoman() when you copy and pasted your solution?

Yes, I did. I’m wondering if other console.log() calls might be affecting it.

I’m so sorry! I don’t know what made me remember (incorrectly) that console.log() would affect the function call (I just tested that it doesn’t).

I’m not entirely sure why this is happening, but I was moving things around (so that everything is contained by convertToRoman() and found that the global variables and romanFactors() seem to be the problem here. I hope someone can comment on this!

It seems that your algorithm doesn’t work for some numbers, too. :frowning:

Good luck!

Yea I have come to find that for numbers above 100 there are some faults. I’ll fix it, but I just need FCC to recognize the ones that are right for now.

Yes, global variables usually cause problems.

As far as I know it is just the function that gets called several times (for all the tests), so global variables are not reset for every function call (every test).

EDIT: Putting romanFactors() and the global variables inside convertToRoman() does indeed work. It will still fail for some cases, but it works the same as on JSBin.

EDIT 2: Just emptying the global variables inside convertToRoman() works as well:

function convertToRoman(num) {
  counter = [];
  romanNumeral = [];
  factorArray = [];
  ...
  ...
}
1 Like

Thanks guys I got it to work. That was fun.