Roman Numeral Converter helppppp

Tell us what’s happening:
Describe your issue in detail here.
hello,
when i run the test it get me that i have wrong output i mean (X sign ) that means it is worng
i console.log every output in each case and i am getting the write answer but some how it doesn’t work when i run the test

   **Your code so far**

let final = [];
function convertToRoman(num) {
 if(num <1){ 
return ;
 }
 let arr = [1000,900,500,400,100,90,50,40,10,9,5,4,1];
 let x = {
   1:'I',
   4:'IV',
   5:'V',
   9:'IX',
   10:'X',
   40: 'XL',
   50:'L',
   90: 'XC',
   100:'C',
   400: 'CD',
   500:'D',
   900: 'CM',
   1000:'M'
 };

let theBaseNumber = arr.find(a=> a<num || a == num);
final.push(x[theBaseNumber]);
convertToRoman(num-theBaseNumber);
return final.join('');
}
convertToRoman(649);

   **Your browser information:**

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

Challenge: Roman Numeral Converter

Link to the challenge:

right i am too bad at English and coding somehow xd

Your code contains global variables that are changed each time the function is run. This means that after each test completes, subsequent tests start with the previous value. To fix this, make sure your function doesn’t change any global variables, and declare/assign variables within the function if they need to be changed.

Example:

var myGlobal = [1];
function returnGlobal(arg) {
  myGlobal.push(arg);
  return myGlobal;
} // unreliable - array gets longer each time the function is run

function returnLocal(arg) {
  var myLocal = [1];
  myLocal.push(arg);
  return myLocal;
} // reliable - always returns an array of length 2
1 Like

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