Code not completing

Tell us what’s happening:
It does not work…

   **Your code so far**

let str = []

function convertToRoman(num) {
 if(num >= 1000){
   str.push('M')
   convertToRoman(num - 1000)
 }

 if(num >= 900 && num < 1000) {
   str.push('CM')
   convertToRoman(num - 900)
 }

 if(num >= 800 && num < 900) {
   str.push('DCCC')
   convertToRoman(num - 800)
 }

 if(num >= 700 && num < 800) {
   str.push('DCC')
   convertToRoman(num - 700)
 }

 if(num >= 600 && num < 700) {
   str.push('DC')
   convertToRoman(num - 600)
 }

 if(num >= 500 && num < 600) {
   str.push('D')
   convertToRoman(num - 500)
 }

 if(num >= 400 && num < 500) {
   str.push('CD')
   convertToRoman(num - 400)
 }

 if(num >= 300 && num < 400) {
   str.push('CCC')
   convertToRoman(num - 300)
 }

 if(num >= 200 && num < 300) {
   str.push('CC')
   convertToRoman(num - 200)
 }

 if(num >= 100 && num < 200) {
   str.push('C')
   convertToRoman(num - 100)
 }

 if(num >= 90 && num < 100) {
   str.push('XC')
   convertToRoman(num - 90)
 }

 if(num >= 80 && num < 90) {
   str.push('LXXX')
   convertToRoman(num - 80)
 }

 if(num >= 70 && num < 80) {
   str.push('LXX')
   convertToRoman(num - 70)
 }

 if(num >= 60 && num < 70) {
   str.push('LX')
   convertToRoman(num - 60)
 }

 if(num >= 50 && num < 60) {
   str.push('L')
   convertToRoman(num - 50)
 }

 if(num >= 40 && num < 50) {
   str.push('XL')
   convertToRoman(num - 40)
 }

 if(num >= 30 && num < 40) {
   str.push('XXX')
   convertToRoman(num - 30)
 }

 if(num >= 20 && num < 30) {
   str.push('XX')
   convertToRoman(num - 20)
 }

 if(num >= 10 && num < 20) {
   str.push('X')
   convertToRoman(num - 10)
 }

 switch (num) {
   case 9:
     str.push('IX')
     break
   case 8:
     str.push('VIII')
     break
   case 7:
     str.push('VII')
     break
   case 6:
     str.push('VI')
     break
   case 5:
     str.push('V')
     break
   case 4:
     str.push('IV')
     break
   case 3:
     str.push('III')
     break
   case 2:
     str.push('II')
     break
   case 1:
     str.push('I')
 }

return str.join('');
}

convertToRoman(68)
   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36

Challenge: Roman Numeral Converter

Link to the challenge:

First off, this shouldn’t be a global variable, and it shouldn’t be named str since str is a keyword.

1 Like

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