function convertToRoman(num) {
var toTen = ["", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X"];
var toHungred = ["", "X" ,"XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC", "C"];
var toThousend = ["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM", "M"];
var arrString = String(num).split("");
var arr = [];
if (arrString.length == 3 ){
arr.push(toThousend[arrString[+0]]);
arr.push(toHungred[arrString[+1]]);
arr.push(toTen[arrString[+2]]);
}
else if (arrString.length == 2 ){
arr.push(toHungred[arrString[+0]]);
arr.push(toTen[arrString[+1]]);
}
else if (arrString.length == 1 ){
arr.push(toTen[arrString[+0]]);
}
else if (arrString.length == 4 ) {
for (var i =1; i<=[arrString[+0]]; i++) {
arr.push("M");
}
arr.push(toThousend[arrString[+1]]);
arr.push(toHungred[arrString[+2]]);
arr.push(toTen[arrString[+3]]);
}
console.log (arr.join(""));
}
convertToRoman(36);