← Back to challenges

Roman Numeral Conversion

JavaScriptHardalgorithmsstringsnumbers

Instructions

Create a function that will take either a string containing a roman numeral, or an integer.

  1. Given a string, return the integer value of that roman numeral.
  2. Given an integer, return the equivalent roman numeral.

Symbols to Values

I ➞ 1

V ➞ 5

X ➞ 10

L ➞ 50

C ➞ 100

D ➞ 500

M ➞ 1000

Examples

romanNumerals("V") ➞ 5

romanNumerals("IV") ➞ 4

romanNumerals("CII") ➞ 102

romanNumerals(45) ➞ "XLV"

romanNumerals(1666) ➞ "MDCLXVI"

Notes

Numerical and Roman Numeral inputs will be positive numbers between 1 and 9999.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.