Roman Numerator Converter Help Please

Okay so I know my solution to this challenge sucks, but it should work for all of the test cases provided. Can someone please tell me why it does not for the case the at the bottom? Any help will be greatly appreciated! :smiley:

function convertToRoman(num) {

var romanNumArray = [];
var number = num;

if (number >= 1000) {
while (number >= 1000) {
romanNumArray.push(“M”);
number -= 1000;
}
}

if (number >= 900) {
while (number >= 900) {
romanNumArray.push(“CM”);
number -= 900;
}
}

if (number >= 500) {
while (number >= 500) {
romanNumArray.push(“D”);
number -= 500;
}
}

if (number >= 400) {
while (number >= 400) {
romanNumArray.push(“CD”);
number -= 400;
}
}

if (number >= 500) {
while (number >= 500) {
romanNumArray.push(“D”);
number -= 500;
}
}

if (number >= 100) {
while (number >= 100) {
romanNumArray.push(“C”);
number -= 100;
}
}

if (number >= 90) {
while (number >= 90) {
romanNumArray.push(“XC”);
number -= 90;
}
}

if (number >= 50) {
while (number >= 50) {
romanNumArray.push(“L”);
number -= 50;
}
}

if (number >= 40) {
while (number >= 40) {
romanNumArray.push(“XL”);
number -= 40;
}
}

if (number >= 10) {
while (number >= 10) {
romanNumArray.push(“X”);
number -= 10;
}
}

if (number >= 9) {
while (number >= 9) {
romanNumArray.push(“IX”);
number -= 500;
}
}

if (number >= 5) {
while (number >= 5) {
romanNumArray.push(“V”);
number -= 5;
}
}

if (number >= 4) {
while (number >= 4) {
romanNumArray.push(“IV”);
number -= 4;
}
}

if (number >= 0) {
while (number >= 1) {
romanNumArray.push(“V”);
number -= 1;
}
}

return romanNumArray.join("");

}
convertToRoman(2);

The problem was with my last if statement…I just needed to push the correct character into the array. This is bad coding practice though right? I feel dumb…like I should find a better solution since I used so many lines of code. :frowning: