Concatenating strings with a switch statement

Working on the Roman Numeral Converter challenge and having an issue: my switch statement isn’t concatenating the roman numerals into the rome variable that I declared at the beginning of the function. I think my issue might have to do with the scope of the rome variable though. Thanks in advance!

Here’s a sample of my code:

function convertToRoman(num) {
  let rome = "";
  let numString = (num).toString(); 
 for (var i=0; i <= numString.length; i++) {
switch (numString[numString.length-1){
      case 1: rome.concat("I");
      case 2: rome.concat("II");
      case 3: rome.concat("III");
      case 4: rome.concat("IV");
      case 5: rome.concat("V");
      case 6: rome.concat("VI");
      case 7: rome.concat("VII");
      case 8: rome.concat("VIII");
      case 9: rome.concat("XI");

Double check how concat works:

Side note - you don’t have to pay extra for full words in variable names. Go ahead and make clear variable names that will be easily understood by others (or yourself in 6 months)!

Thanks for the tips, Jeremy, I appreciate it. Is the issue that concatenation creates a new string, but doesn’t the original variable?

Could I then use a += instead? That would seem to assign a new value to the rome variable.

It would indeed. One way or another you need to assign the updated value with an =

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.