# Roman Numeral problem (renewed)

**URL:** <https://forum.freecodecamp.org/t/roman-numeral-problem-renewed/196597>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [June 4, 2018, 11:23pm UTC](https://forum.freecodecamp.org/t/roman-numeral-problem-renewed/196597 "2018-06-04T23:23:30Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![JM-Mendez](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jm-mendez/32/33681_2.png) [@JM-Mendez](https://forum.freecodecamp.org/u/JM-Mendez)\
**Post date:** [June 5, 2018, 10:09pm UTC](https://forum.freecodecamp.org/t/roman-numeral-problem-renewed/196597/3 "2018-06-05T22:09:52Z")

</div>

Ok, what you’re witnessing is a closure problem since you declared your variables using `var`. And since console.log is a function, it will only have access to the global `romarr` when the loop finishes.

Why codepen’s console is different is due to their code. I think they hijack the console rather than show the actual log.

I explained closures in this other response. Closures are a complicated topic, so if that answer doesn’t work for you, tell me what I didn’t make clear.

> [@Function inside for loop](https://forum.freecodecamp.org/t/function-inside-for-loop/195973/4):
>
> This is due to closures. Essentially in javascript, unlike other languages, functions have access to anything in their scope after they return. So what happens when you use var is that the variable is bound to the global scope, and every function has access to it. When we finally call printNumTwo, it still can only access the global i at the moment you call it, which will be 3, since the loop ends when it reaches 3. I find it helps me to walk through how the js engine runs this code, line by…

---

_[View the full topic](https://forum.freecodecamp.org/t/roman-numeral-problem-renewed/196597)._
