Cuéntanos qué está pasando:
Mi código funciona con cada uno de los ejemplos dado en la rubrica, pero por alguna razón no pasa la prueba, me podrían ayudar con ese detalle, no se cual sea el problema que no me deja seguir.
Tu código hasta el momento
function romanize(num) {
let thousands = Math.trunc(num/1000) % 10;
let hundred = Math.trunc(num/100) % 10;
let tenth = Math.trunc(num/10) % 10;
let unity = Math.trunc(num/1) % 10;
let romNumber = [];
if(thousands > 3){
return "That is not a number";
} else {
switch(thousands){
case 1:
romNumber.push("M");
break;
case 2:
romNumber.push("MM");
break;
case 3:
romNumber.push("MMM");
break;
}
switch(hundred){
case 1:
romNumber.push("C");
break;
case 2:
romNumber.push("CC");
break;
case 3:
romNumber.push("CCC");
break;
case 4:
romNumber.push("CD");
break;
case 5:
romNumber.push("D");
break;
case 6:
romNumber.push("DC");
break;
case 7:
romNumber.push("DCC");
break;
case 8:
romNumber.push("DCCC");
break;
case 9:
romNumber.push("CM");
break;
}
switch(tenth){
case 1:
romNumber.push("X");
break;
case 2:
romNumber.push("XX");
break;
case 3:
romNumber.push("XXX");
break;
case 4:
romNumber.push("XL");
break;
case 5:
romNumber.push("L");
break;
case 6:
romNumber.push("LX");
break;
case 7:
romNumber.push("LXX");
break;
case 8:
romNumber.push("LXXX");
break;
case 9:
romNumber.push("XC");
break;
}
switch(unity){
case 1:
romNumber.push("I");
break;
case 2:
romNumber.push("II");
break;
case 3:
romNumber.push("III");
break;
case 4:
romNumber.push("IV");
break;
case 5:
romNumber.push("V");
break;
case 6:
romNumber.push("VI");
break;
case 7:
romNumber.push("VII");
break;
case 8:
romNumber.push("VIII");
break;
case 9:
romNumber.push("IX");
break;
}
return romNumber.join('');
}
}
console.log(romanize(3999));
Información de tu navegador:
El agente de usuario es: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36
Desafío: Algoritmos de JavaScript y proyectos de estructuras de datos - Conversor de números romanos
Enlaza al desafío: