# Post your Roman Numeral Converter solutions here! (Fall 2022)

**URL:** <https://group.classcentral.com/t/post-your-roman-numeral-converter-solutions-here-fall-2022/35779>\
**Category:** JavaScript Bootcamp\
**Created:** [September 21, 2022, 8:30am UTC](https://group.classcentral.com/t/post-your-roman-numeral-converter-solutions-here-fall-2022/35779 "2022-09-21T08:30:22Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![tusharmunge2610775](https://sea2.discourse-cdn.com/flex016/user_avatar/group.classcentral.com/tusharmunge2610775/32/5939_2.png) [@tusharmunge2610775](https://group.classcentral.com/u/tusharmunge2610775)\
**Post date:** [September 22, 2022, 5:22am UTC](https://group.classcentral.com/t/post-your-roman-numeral-converter-solutions-here-fall-2022/35779/18 "2022-09-22T05:22:49Z")

</div>

Here is my solution to Roman Numeral Converter.  
Cheers, T.

```auto
const RomanArabicMapping = {
  M: 1000,
  CM: 900,
  D: 500,
  CD: 400,
  C: 100,
  XC: 90,
  L: 50,
  XL: 40,
  X: 10,
  IX: 9,
  V: 5,
  IV: 4,
  I: 1,
};

const convertToRoman = number => {
  let strRoman = "";

  // Loop through all the Object Properties
  for (const keyRoman in RomanArabicMapping) {
    // Construct the Roman numeral for the current Key
    while (number >= RomanArabicMapping[keyRoman]) {
      strRoman += keyRoman;
      number -= RomanArabicMapping[keyRoman];
    }
  }

  // Take care of "0" being passed
  return (strRoman === "" ? "Unknown" : strRoman);
}

console.log(convertToRoman(2)); //should return the string II.
console.log(convertToRoman(3)); //should return the string III.
console.log(convertToRoman(4)); //should return the string IV.
console.log(convertToRoman(5)); //should return the string V.
console.log(convertToRoman(9)); //should return the string IX.
console.log(convertToRoman(12)); //should return the string XII.
console.log(convertToRoman(16)); //should return the string XVI.
console.log(convertToRoman(29)); //should return the string XXIX.
console.log(convertToRoman(44)); //should return the string XLIV.
console.log(convertToRoman(45)); //should return the string XLV.
console.log(convertToRoman(68)); //should return the string LXVIII
console.log(convertToRoman(83)); //should return the string LXXXIII
console.log(convertToRoman(97)); //should return the string XCVII
console.log(convertToRoman(99)); //should return the string XCIX
console.log(convertToRoman(400)); //should return the string CD
console.log(convertToRoman(500)); //should return the string D
console.log(convertToRoman(501)); //should return the string DI
console.log(convertToRoman(649)); //should return the string DCXLIX
console.log(convertToRoman(798)); //should return the string DCCXCVIII
console.log(convertToRoman(891)); //should return the string DCCCXCI
console.log(convertToRoman(1000)); //should return the string M
console.log(convertToRoman(1004)); //should return the string MIV
console.log(convertToRoman(1006)); //should return the string MVI
console.log(convertToRoman(1023)); //should return the string MXXIII
console.log(convertToRoman(2014)); //should return the string MMXIV
console.log(convertToRoman(3999)); //should return the string MMMCMXCIX

```

---

_[View the full topic](https://group.classcentral.com/t/post-your-roman-numeral-converter-solutions-here-fall-2022/35779)._
