Type Error in my Roman Numeral code

Tell us what’s happening:
I am getting the error “TypeError: undefined is not an object (evaluating ‘table[i][0]’)” where my code is trying to push the Roman numeral (as a string) found at table[i][0] to an array holding my roman numerals.

I can’t figure out why or how to fix it.

P.S. My code is clunky. I just wanted to get it to work before making a better algorithm.

Your code so far



function convertToRoman(num) {

let table = [
['I', 'V', 'X'],
['X', 'L', 'C'],
['C', 'D', 'M']];
console.log(table);
console.log(table[0])
console.log(table[1][2])

let numberArray = num
.toString(10)
.split('')
.reverse();

console.log(numberArray)
console.log(numberArray[0])

let returnArray = [];

for (let i=0; i<numberArray.length; i++) {
console.log(numberArray[i])
if (numberArray[i] = '0') {};
if (numberArray[i] = '1') {
  returnArray.unshift(table[i][0]);
};
if (numberArray[i = '2']) {
  returnArray.unshift(table[i][0]);
  returnArray.unshift(table[i][0]);
};
if (numberArray[i] = '3') {
  returnArray.unshift(table[i][0]);
  returnArray.unshift(table[i][0]);
  returnArray.unshift(table[i][0]);
};
if (numberArray[i = '4']) {
  returnArray.unshift(table[i][1]);
  returnArray.unshift(table[i][0]);
};
if (numberArray[i = '5']) {
  returnArray.unshift(table[i][1]);
};
if (numberArray[i] = '6') {
  console.log(table[i][0]);
  returnArray.unshift(table[i][0]);
  returnArray.unshift(table[i][1]);
};
if (numberArray[i = '7']) {
  returnArray.unshift(table[i][0]);
  returnArray.unshift(table[i][0]);
  returnArray.unshift(table[i][1]);
};
if (numberArray[i] = '8') {
  returnArray.unshift(table[i][0]);
  returnArray.unshift(table[i][0]);
  returnArray.unshift(table[i][0]);
  returnArray.unshift(table[i][1]);
};
if (numberArray[i = '9']) {
  returnArray.unshift(table[i][2]);
  returnArray.unshift(table[i][0]);
};
}

return returnArray.toString();
}

convertToRoman(36);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15.

Challenge: Roman Numeral Converter

Link to the challenge:

Hello there,

Your main issue is this logic:

if (numberArray[i] = '0')

I am not going to tell you the exact problem, because I suspect you just overlooked it, but there is a very simple fix to this…

Hope that helps