Tell us what’s happening:
I have almost completed this challenge. And I got all the test to pass by add values 2000 = MM and 3000 = MMM to my romanNumerals object. Any ideas on how to get values > 1999 to repeat M without adding 2000, and 3000 to my romanNumeral object.
**Your code so far**
function convertToRoman(num) {
/*Create a table of Roman numerals */
const romanNumerals = {
0: '',
1 : "I",
2: "II",
3: "III",
4: "IV",
5: 'V',
6: "VI",
7: "VII",
8: "VIII",
9: "IX",
10: "X",
20: "XX",
30: "XXX",
40: "XL",
50: "L",
60: "LX",
70: "LXX",
80: "LXXX",
90: "XC",
100: "C",
200: "CC",
300: "CCC",
400: "CD",
500: "D",
600: "DC",
700: "DCC",
800: "DCCC",
900: "CM",
1000: "M",
2000:'MM',
3000: 'MMM',
}
/* Convert Number to String */
const numArr = num.toString().split('').map(ele => ele= [ele]);
/* Convert Numbers to place Values */
let placeValue = [];
for(let i = 0; i < numArr.length; i++ ){
placeValue.push(numArr[i] + '0'.repeat(numArr.length - 1 - i))
}
/*Replace place values of '0' repeating > 1 time to '0 */
for(let ele in placeValue){
if(ele === '0'> 1){
ele = 0;
}
};
/*Create a variable to hold romanNumeral string */
let romanNumeral = ""
/* Found cooresponding roman numeral value and used array.map and array.join to return roman numeral string */
romanNumeral =(placeValue.map(function(element){
if(element > 1000){
return element = romanNumerals[element].repeat(element/1000)
} else{
return element = romanNumerals[element]
}
})
).join('')
console.log(romanNumeral)
return romanNumeral;
}
convertToRoman(36);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36
Challenge: Roman Numeral Converter
Link to the challenge: