# Roman Numeral Converter code is not executing properly

Tell us what’s happening:
my code is working correctly for 1 to 100; and for numbers greater than 1000; but in between it is not working. why?
any mistakes in my code?
please help me …

Your code so far

``````
function convertToRoman(num) {
var a=num%10;
var b = (num -a)/10;
var c = (num-(b*10))/100;
var d = (num-(c*100))/1000;
let str="";

switch(d) {
case 1:
str = str+"M";
break;
case 2:
str =str+"MM";
break;
case 3:
str =str+"MMM";
break;
}

switch(c) {
case 1:
str =str+"C";
break;
case 2:
str =str+"CC";
break;
case 3:
str =str+"CCC";
break;
case 4:
str =str+"CD";
break;
case 5:
str =str+"D";
break;
case 6:
str =str+"DC";
break;
case 7:
str =str+"DCC";
break;
case 8:
str =str+"DCCC";
break;
case 9:
str =str+"CM";
break;
}

switch(b) {
case 1:
str =str+"X";
break;
case 2:
str =str+"XX";
break;
case 3:
str =str+"XXX";
break;
case 4:
str =str+"XL";
break;
case 5:
str =str+"L";
break;
case 6:
str =str+"LX";
break;

case 7:
str =str+"LXX";
break;
case 8:
str =str+"LXXX";
break;
case 9:
str =str+"XC";
break;
}

switch(a) {
case 1:
str =str+"I";
break;
case 2:
str =str+"II";
break;

case 3:
str =str+"III";
break;
case 4:
str =str+"IV";
break;
case 5:
str =str+"V";
break;
case 6:
str =str+"VI";
break;
case 7:
str =str+"VII";
break;
case 8:
str =str+"VIII";
break;
case 9:
str =str+"IX";
break;
}
return str;

}

convertToRoman(891);

``````

Your browser information:

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36`.

You are not rounding the numbers so none of the integers are found in the switch statements.