An easy way I try to find that I wrote some code partially works but not for all challenges. Please help to correct my coding.
’’'
function convertToRoman(num) {
var index=0;
var number=0;
var romans="";
var numberRomans=[“I”,“IV”,“V”,“IX”,“X”,“XL”, “L”,“XC”,“C”,“CD”,“D”,“CM”,“M”];
for(index=0;index<numberRomans.length;index++){
for(num=1;num<numberRomans.length;number++){
if(num){
romans+=numberRomans[index];
}
}
}
return romans;
}
You have num as function parameter and then you are assigning num = 1 (basically losing your function’s input value) in second for loop and never changing the num so your second for loop is running forever.
I corrected it now but the second for loop is still overflow. Actualy the code works for only 13 steps and not for the others
function convertToRoman(num) {
var index=0;
var romans="";
var numberRomans=[“I”,“IV”,“V”,“IX”,“X”,“XL”, “L”,“XC”,“C”,“CD”,“D”,“CM”,“M”];
for(index=0;index<numberRomans.length;index++){
while(num++){
if(num){
romans+=numberRomans[index];
}
}
}
return romans;
}