# Roman Numeral Converter works for all numbers except the ones ending in 9

Can someone explain why my code works for every number except the ones ending in 9?

Code:

``````function convertToRoman(num) {
//declare a holder variable to be used for storing roman num
var romanNum = "";

while (num > 0){
console.log(num)
if (num >= 1000){
num -= 1000;
romanNum += "M";
} else if (num >= 900){
num -= 900;
romanNum += "CM";
} else if (num >= 500){
num -= 500;
romanNum += "D";
} else if(num >= 400){
num -= 400;
romanNum += "CD";
} else if (num >= 100){
num -= 100;
romanNum += "C";
} else if (num >= 90){
num -= 90;
romanNum += "XC";
} else if (num >= 50){
num -= 50;
romanNum += "L";
} else if (num >= 40){
num -= 40;
romanNum += "XL";
} else if (num >= 10){
num -= 10;
romanNum += "X";
} else if (num == 9){
num -= 9;
romanNum = "IX";
}else if (num >= 5){
num -= 5;
romanNum += "V";
}else if (num == 4){
num -= 4;
romanNum += "IV";
} else if (num >= 1){
num -= 1;
romanNum += "I";
};
}
return romanNum;
}
``````

I know the code is far from optimal, but I wanted to solve it with a basic solution first. However it can’t pass the tests ending in 9.

Change `romanNum = "IX";`
To `romanNum += "IX";`