My code is right but it keeps saying infinite loop. Is it beacause it takes too long?

Tell us what’s happening:
Describe your issue in detail here.

   **Your code so far**

function convertToRoman(num) {
 var result =""
 var table ={
   1:"I",
   4:"IV",
   5:"V",
   9:"IX",
   10:"X",
   40:'XL',
   50:"L",
   90:"XC",
   100:'C',
   400:"CD",
   500:"D",
   900:"CM",
   1000:"M"};

var numList = Object.keys(table);

while (num!=0){
   for(var i =0;i<numList.length;i++){
     if(num==numList[i]){
       result+=table[numList[i]]
       num= num-numList[i]
       

       break
     }
     else if(num<numList[i]){
       result += table[numList[i-1]]
       num = num -numList[i-1]
       

       break
     }
   }
   
 }

return result;
}





console.log(convertToRoman(100));
   **Your browser information:**

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

Challenge: Roman Numeral Converter

Link to the challenge:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.