What's wrong with my switch for the Roman Numeral Converter challenge?

I’m sure there easier and more efficient ways to do this challenge, but I would like to know how I messed up my way! So why isn’t this way giving me any results for hundR? The console returns nothing.

function convertToRoman(num) {
 var arr = [];
  //convert number to string to array
  num = num + "";
  arr = num.split("");
  //split number into groups
  var thou = (arr[arr.length - arr.length]);
  var hund = (arr[arr.length - (arr.length-1)]);
  var tens = (arr[arr.length - (arr.length-2)]);
  var ones = (arr[arr.length - (arr.length-3)]);
  //changes groups into roman
    //thousands
  var thouR = "";
  for (var i = 0; i < thou ; i++){
   thouR += "M";  
  }
    //hundreds
  var hundR = "";
  switch (hund){
    case 0:
    case 1:
    case 2:
    case 3:
      for (var j = 0; j < hund ; j++){
        hundR += "C";
      } 
    break;
    case 4:
      hundR = "CD";
      break;
    case 5:
    case 6:
    case 7:
    case 8:
      hundR = "D";
      for (var k = 5; k < hund ; k++){
   hundR += "C";  
      }
      break;
    case 9:
      hundR = "CM";
      break;  
  }
  
  
  return hundR;
  
}

convertToRoman(3399);

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

1 Like

Thanks for doing that, I’ll check out that post.

Your switch cases are looking for numbers(number type).Switch case is using strict equality).The variable hund is a string.

btw arr.length - arr.length is always zero - you can simplify the digits to

let thou=arr[0]
let hund=arr[1]

the reason is switch uses strict equality ===

this means hund which is the string "3" does not match case 3: which has the number 3

Change to

let hund=parseInt(arr[1], 10)

Thank you, appreciate the help.

That was silly of me, thanks for the help!