Tell us what’s happening:
Describe your issue in detail here.
I don’t understand why this is giving me an error. I thought maybe it had to do with it not being a string so I did try to use a convert .toString() as well in case that fixed the issue but it’s still failing. I’m seeing the output as correct though. I don’t want the answer cause it is a challenge but I am curious if you’re seeing an issue here that tells you it doesn’t work. I did run this in VSCode to make sure and it seems to run fine as output if I console.log it out.
snowmonkey is right.
For all the tests, remember to turn the function call into a console.log(convertToRoman('2'))
This way you actually see what your code produces and if you call it several times, you’ll see the problem with global variables.
Generally: NEVER use globals UNLESS it’s a constant.
Ah shoot. I never thought about it being called more than once. I didn’t see it cause I kept testing the console.log but only by changing the one call, not multiple calls
Good ^^
Yeah this it kind of the issue with recursions, if you want to add values.
You could try wrapping the recursion into another function where you declare the romanConverted variable. I think that should work.
Though honestly, your solution for the most part is basically a while-loop with extra steps. So if you feel like your solution is dirty, just try transforming it into an actual while-loop