I mean this →
units function doesn’t seem to be built to accept parameters and i variable is not defined when referenced in units function. Am I right?
It seems to work in Chrome Dev Tools but in challenge editor it returns this:
function convertToRoman(num) {
var romans = ["I", "V", "X", "L", "C", "D", "M"],
ints = [],
romanNumber = [],
numeral = "";
while (num) {
ints.push(num % 10);
num = Math.floor(num / 10);
}
console.log(num%10)
console.log(ints)
for (i = 0; i < ints.length; i++) {
units(ints[i]);
}
function units() {
numeral = romans[i * 2];
switch (ints[i]) {
case 1:
romanNumber.push(numeral);
break;
case 2:
romanNumber.push(numeral.concat(numeral));
break;
case 3:
romanNumber.push(numeral.concat(numeral).concat(numeral));
break;
case 4:
romanNumber.push(numeral.concat(romans[i * 2 + 1]));
break;
case 5:
romanNumber.push(romans[i * 2 + 1]);
break;
case 6:
romanNumber.push(romans[i * 2 + 1].concat(numeral));
break;
case 7:
romanNumber.push(romans[i * 2 + 1].concat(numeral).concat(numeral));
break;
case 8:
romanNumber.push(
romans[i * 2 + 1]
.concat(numeral)
.concat(numeral)
.concat(numeral)
);
break;
case 9:
romanNumber.push(romans[i * 2].concat(romans[i * 2 + 2]));
}
}
return romanNumber
.reverse()
.join("")
.toString();
}
// test here
convertToRoman(3000);
return
0
[ 0, 0, 0, 3 ]
ReferenceError: i is not defined
How this is working in Chrome ?