# Roman Numerals alg. I am getting zero passes when it works

There’s a few things not perfect, but “3” for example returns exactly what they’re looking for but it still doesn’t pass the test?
ps, I realize I used about 10X the amount of code I should have. I’m at a loss. Any ideas? I feel like the tests aren’t working properly, or I’m doing something just slightly off. I know there’s a few issues, but like I said, at least the first 3 tests return exactly what they wanted.

``````var result = [];
function convertToRoman(num) {
var newNum = [];
pushOnes(num);
pushFives(num);
pushTens(num);
pushHundreds(num);
pushThousands(num);
result.reverse();
num = result.join('');
return num;
}
//1-5
function pushOnes(num){
var ones = num%5;
if (ones != 4){
for (var i = 0; i < ones; i++){
result.push('I');
}
} else {
result.push('IV');
}
return num - ones;
}
//5-9
function pushFives(num){
var fives = num %10;
if (fives > 4 && fives < 9){
result.push('V');
}else if(fives == 9){
result.push('IV');
}
}
//10-90
function pushTens(num){
var tens = num % 100;
if (tens < 40){
for(var j = 0; j < Math.floor(tens/10); j++){
result.push('X');
}
}else if(tens > 40 && tens <= 50){
result.push('L');
}else if(tens >= 60 && tens < 90){
result.push('L');
for(var k = 0; k < Math.floor((tens/10)-5); k++){
result.push('X');
}
}else {
result.push('XC');
}
}
//100-900
function pushHundreds(num){
var hundreds = num%1000;
if (hundreds < 400){
for(var l = 0; l < (Math.floor(hundreds / 100)); l ++){
result.push('C');
}
}else if(hundreds >= 400 && hundreds <= 500){
result.push('D');
}else if(hundreds < 900 && hundreds > 500){
for(var p = 0; p < ((Math.floor(hundreds / 100)) -5 ); p++){
result.push('C');
}
result.push('D');
}
}
//1000+
function pushThousands(num){
var thousands = Math.floor(num / 1000);
for(var e = 0; e < thousands; e++){
result.push('M');
}
}

convertToRoman(4);``````

One rule of these test suites, is never have global variables. Your variable result is getting inherited by each test. It should be inside convertToRoman(). Consequently, any function that uses result will also have to be inside convertToRoman() so they can access result. When I do that, it starts working for many of the cases.

In general, global variables should be avoided. It’s best if variables have as narrow a scope as is reasonably possible.

Thank you! I’ll make those changes and give it another shot. Thank you so much!

Thank worked. Well it made it pass the tests that it should! I still have some things to fix. Thanks agian!