Tell us what’s happening:
I am unable to pass any of the tests although the output generated is correct…please help…cant figure out whats wrong
Your code so far
var arr1=[1,2,3,4,5,6,7,8,9,10,40,50,90,100,400,500,900,1000,2000,3000,4000];
var arr2=['I','II','III','IV','V','VI','VII','VIII','IX','X','XL','L','XC','C','CD','D','CM','M','MM','MMM','MMMM'];
var res="";
function convertToRoman(num)
{
var found=0;
for(var i=0;i<arr1.length;i++)
{
if(num==arr1[i])
{
found=1;
res=res+arr2[i];
break;
}
}//end of for
if(found==1)//number is found in the array
{
console.log(res);
// return res;
}
else//number not present in the array
{
for(var k=0;k<arr1.length;k++){
if(num>arr1[k]&&num<arr1[k+1])
{
//console.log(arr2[k]);
//console.log(arr2[k+1]);
res=res+arr2[k];
convertToRoman(num-arr1[k]);
}
}
}//end of else
return res;
}//end of convertToRoman
convertToRoman(3999);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/roman-numeral-converter