Why won't my Roman Number Conversion work?

Why won't my Roman Number Conversion work?
0

#1

All my tests return the correct number. Why won’t it work?

var numArr = {
  '0':['','','',''],
  '1':['I', 'X', 'C', 'M'], 
  '2':['II', 'XX', 'CC', 'MM'], 
  '3':['III', 'XXX', 'CCC', 'MMM'], 
  '4':['IV', 'XL', 'CD', 'MV'],
  '5':['V', 'L', 'D', 'V'],
  '6':['VI', 'LX', 'DC', 'VM'],
  '7':['VII', 'LXX', 'DCC', 'VMM'],
  '8':['VIII', 'LXXX', 'DCCC', 'VMMM'],
  '9':['IX', 'XC', 'CM', 'MX']
},
	newNum =[];

function convertToRoman(num) {
  var res = num.toString().split("");
  res.reverse();
  for (var i = res.length - 1; i >= 0; i--) {
		newNum.push(numArr[res[i]][i]);
  }
  newNum = newNum.join('');
  return newNum;
}

convertToRoman(798);

#2

It’s because you’re declaring the newNum variable in the global namespace. Try moving your variables inside your function,so they’re not available outside of its scope and check if it passes the tests.


#3

Right on spot! Thanks a lot.