# Help with: JavaScript Algorithms and Data Structures Projects: Roman Numeral Converter

**URL:** <https://forum.freecodecamp.org/t/help-with-javascript-algorithms-and-data-structures-projects-roman-numeral-converter/226059>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [September 12, 2018, 1:39pm UTC](https://forum.freecodecamp.org/t/help-with-javascript-algorithms-and-data-structures-projects-roman-numeral-converter/226059 "2018-09-12T13:39:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon75977125](https://avatars.discourse-cdn.com/v4/letter/a/54ee81/32.png) [@anon75977125](https://forum.freecodecamp.org/u/anon75977125)\
**Post date:** [September 12, 2018, 1:39pm UTC](https://forum.freecodecamp.org/t/help-with-javascript-algorithms-and-data-structures-projects-roman-numeral-converter/226059/1 "2018-09-12T13:39:48Z")

</div>

So, the solution I thought up for this challenge was to get two arrays (one with the Roman Numerals and the other with the Decimals), join key:value together and then just look up the “num” variable. It works, but, of course, it only works if I get every value possible in both arrays which seems to go agaisnt the nature of the challenge (not to mention agaisnt any actual functionality). Any ideas on how I could improve it?

```function
var arrRoman=["I","IV","V","IX","X","XL","L","C","D","M"];
var arrNumbers=[1,4,5,9,10,40,50,100,500,1000];
var comparison= {};
for (var i = 0; i < arrRoman.length; i++)
    comparison[arrNumbers[i]] = arrRoman[i];
return (comparison[num]);
}

convertToRoman(36);
```

---

<div class="post-metadata">

**Author:** ![moT01](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mot01/32/417588_2.png) [@moT01](https://forum.freecodecamp.org/u/moT01)\
**Post date:** [September 12, 2018, 2:20pm UTC](https://forum.freecodecamp.org/t/help-with-javascript-algorithms-and-data-structures-projects-roman-numeral-converter/226059/2 "2018-09-12T14:20:43Z")

</div>

I would consider using a `while` loop and either count down from your number to 0, or up from 0 to your number

---

<div class="post-metadata">

**Author:** ![anon75977125](https://avatars.discourse-cdn.com/v4/letter/a/54ee81/32.png) [@anon75977125](https://forum.freecodecamp.org/u/anon75977125)\
**Post date:** [September 12, 2018, 2:23pm UTC](https://forum.freecodecamp.org/t/help-with-javascript-algorithms-and-data-structures-projects-roman-numeral-converter/226059/3 "2018-09-12T14:23:40Z")

</div>

That sounds promising, thank you for the input. The only issue I see with that is that I would have to implement a lot of rules for non-linear numbers (like 4=IV, etc).

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [February 2, 2021, 11:31am UTC](https://forum.freecodecamp.org/t/help-with-javascript-algorithms-and-data-structures-projects-roman-numeral-converter/226059/4 "2021-02-02T11:31:00Z")

</div>

Closed on February 2, 2021, 11:31am UTC


