`` function convertToRoman(num) {
//Check for the units
UnitsRoman = ["I","II","III","IV","V","VI","VII", "VIII", "IX"];
UnitsNorm = ["1","2","3","4","5","6","7", "8", "9"];
TensRoman = ["X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"];
TensNorm = ["10", "20", "30", "40", "50", "60", "70", "80", "90"];
HundredsRoman = ["C", "CC", "CCC", "CD","D", "DC", "DCC", "DCCC", "CM"];
HundredsNorm = ["100", "200", "300", "400","500", "600", "700", "800", "900"];
ThousandRoman = ["M", "MM", "MMM", "","D", "DC", "DCC", "DCCC", "CM"];
ThousandNorm = ["1000", "2000", "3000", "400","500", "600", "700", "800", "900"];
var newNum;
arrNum = num.toString();
arrNum = arrNum.split("");
console.log(arrNum.length);
switch (arrNum.length){
case 1:
newNum = UnitsRoman[UnitsNorm.indexOf(arrNum[0])];
break;
case 2:
if(arrNum[1] === "0"){
newNum = TensRoman[UnitsNorm.indexOf(arrNum[0])]
}else{
newNum = TensRoman[UnitsNorm.indexOf(arrNum[0])] + UnitsRoman[UnitsNorm.indexOf (arrNum[1])];
}
break;
case 3:
if(arrNum[2] === "0" && arrNum[1] === "0"){
newNum = HundredsRoman[UnitsNorm.indexOf(arrNum[0])];
}
else if(arrNum[1] === "0"){
newNum = HundredsRoman[UnitsNorm.indexOf(arrNum[0])] + UnitsRoman[UnitsNorm.indexOf(arrNum[2])];
}
else{
newNum = HundredsRoman[UnitsNorm.indexOf(arrNum[0])] + TensRoman[UnitsNorm.indexOf(arrNum[1])] + UnitsRoman[UnitsNorm.indexOf (arrNum[2])];
}
break;
case 4:
//1 0 0 0
if(arrNum[1] === "0" && arrNum[2] === "0" && arrNum[3] === "0"){
newNum = ThousandRoman[UnitsNorm.indexOf(arrNum[0])];
}
//1 0 0 1-9
else if(arrNum[1] === "0" && arrNum[2] === "0" && arrNum[3] != "0"){
newNum = ThousandRoman[UnitsNorm.indexOf(arrNum[0])] + UnitsRoman[UnitsNorm.indexOf (arrNum[3])];
}
//1 0 1 6
else if(arrNum[1] === "0" && arrNum[2] != "0" && arrNum[3] != "0"){
newNum = ThousandRoman[UnitsNorm.indexOf(arrNum[0])] + TensRoman[UnitsNorm.indexOf(arrNum[2])] + UnitsRoman[UnitsNorm.indexOf (arrNum[3])] ;
}
else{
newNum = ThousandRoman[UnitsNorm.indexOf(arrNum[0])] + HundredsRoman[UnitsNorm.indexOf(arrNum[1])] + TensRoman[UnitsNorm.indexOf (arrNum[2])] + UnitsRoman[UnitsNorm.indexOf (arrNum[3])];
}
break;
}
return newNum;