Why is my switch() statement not doing it's work?

Tell us what’s happening:
Describe your issue in detail here.

Yes, the current code is hard coded, it’s just a test that failed for some odd reason, I’m trying to add a Roman Numeral value to a string (I already attempted an array, didn’t work) but for some reason it’s not working, not even showing an error.

   **Your code so far**

function convertToRoman(num) {
let arrOfNumbers = []
let finalStr = ''
let stringifiedNumber = num.toString()


for(let i = 0; i < stringifiedNumber.length; i++) {
  let numberOfZeros  = stringifiedNumber.length - (i + 1)
  let newNumber = stringifiedNumber[i] + '0'.repeat(numberOfZeros)
  arrOfNumbers.push(Number(newNumber))
}

for(let i = 0; i < arrOfNumbers; i++) {
  
  switch(arrOfNumbers[i]) {
    case 1000:
     finalStr += 'M'
     break
    case 900:
     finalStr += 'CM'
     break
    case 80:
     finalStr += 'LXXX'
     break
    case 4:
     finalStr += 'IV'
     break
  }

}

console.log(finalStr)
}

convertToRoman(1984);

   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36

Challenge: Roman Numeral Converter

Link to the challenge:

Do you want i to be less than arrOfNumbers (a numeric value), or less than the number of things in arrOfNumbers (the length of an array)?

Sorry for the late reply, kinda had some stuff going on. I want to loop through all the things in the arr, so less than the length of the array.

1 Like

Ok, now I see, I facepalmed hard at this. Thanks for reaching out to me!

1 Like

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