# Roman Numeral Conversion Challenge Infinite Loop

Hi, a little help here. I’ve tried to run through the logic in the program and i don’t see where its getting caught up in a loop. I’ve put //noprotect on and it is getting caught up but idk why. I am also aware the answer is going into an array, i will fix that once i get this sorted out. thanks for any help!

``````function convertToRoman(num) {
var roman = [];
while(num > 0){
if(num >= 1000){
num -= 1000;
roman.append("M");
}
if(1000 > num >= 900){
num -= 900;
roman.append("CM");
}
if(900 > num >= 500){
num -= 500;
roman.append("D");
}
if(500 > num >= 400){
num -= 400;
roman.append("CD");
}
if(400 > num >= 100){
num -= 100;
roman.append("C");
}
if(100 > num >= 90){
num -= 90;
roman.append("XC");
}
if(90 > num >= 50){
num -= 50;
roman.append("L");
}
if(50 > num >= 40){
num -= 40;
roman.append("XL");
}
if(40 > num >= 10){
num -= 10;
roman.append("X");
}
if(10 > num >= 9){
num -= 9;
roman.append("IX");
}
if(9 > num >= 5){
num -= 5;
roman.append("V");
}
if(5 > num >= 1){
num -= 1;
roman.append("I");
}
}
return roman;
}

convertToRoman(36);``````

You need to use triple backticks to post code to the forum.
See this post for details.

I don’t think `if( .. > num > .. )` is valid syntax.

EDIT:
Or maybe it is, but it doesn’t do what you expect.

Expression such as

``````a > b > c
``````

Translates to

``````(a > b) > c
``````

(a > b) yields boolean so its numeric counter part is 0 or 1.
So what you are doing is comparing whatever c is with 0 or 1.

1 Like