I'm trying to pass 'Roman Numeral Converter'

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

I wrote a code, that relly work properly б and returns everythingб that it need to returnб but when i run testб everything failing (i tried to delete whitespaces and so onб it just don’t passes the testб but it’s work correct). You can try my code and ensureб that it is correctб but i don’t know how to pass though.

  **Your code so far**


let numLastArr = [];
function convertToRoman(num) {


const numbers = {
  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' 
}

// converting taken number into roman number
function conv (num, num2) {
  if (num >= 1 && num <= 3) {
    let a = '';
    while (num >= 1){
      a +=  numbers[num2];
      num--;
    }
    return a;
  } else if (num >= 6 && num <= 8){
    let a = '';
    let u = num - 5;
    while (u >= 1) {
      a += numbers[num2];
      u--;
    }
    return numbers[5 * num2] + a;
  }
  return numbers[num2 * num];
}
const myFunc = numer => Number(numer);
let numArr = Array.from(String(num), myFunc);
//if 4 numbers in number
if (numArr.length == 4) {
  let fir = numArr.shift();
  if (fir <= 3) {
  numLastArr.push(conv (fir, (fir * 1000) /fir));
  // call func again
  return convertToRoman(numArr.join(''));
  } 
} else if (numArr.length == 3) {
    let fir = numArr.shift();
  numLastArr.push(conv (fir, (fir * 100) /fir));
  // call func again
  return convertToRoman(numArr.join(''))
  } else if (numArr.length == 2) {
    let fir = numArr.shift();
  numLastArr.push(conv (fir, (fir * 10) /fir));
  // call func again
  return convertToRoman(numArr.join(''))
  } else if (numArr.length == 1) {
    let fir = numArr.shift();
  numLastArr.push(conv (fir, (fir * 1) /fir));
  // call func again
  return convertToRoman(numArr.join(''))
  }

 let b = numLastArr.join('').trim('').replace(/\s+/g, '');
 
 return b;

}

console.log(convertToRoman(1004));
  **Your browser information:**

opera gx

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

Challenge: Chunky Monkey

Link to the challenge:

Hi there Welcome to the forums!
We try to help by giving hints instead of just giving you the answer. The best tip I got was to implement your own testing feature. If you are using vscode or some ide to test your code try adding these lines at the bottom:

const testArray = [1,2,3,4,5,9,12,16,29,44,45,68,83,97,99,400,500,501,649,798,891,1000,1004,1006,1023,2014,3999]

testArray.forEach(test => console.log(convertToRoman(test)));

this will run the test for every number in the array and console.log() the result. When I did it with your code I got the following:

I
III
IIIIII
IIIIIIIV
IIIIIIIVV
IIIIIIIVVIX
IIIIIIIVVIXXII
IIIIIIIVVIXXIIXVI
IIIIIIIVVIXXIIXVIXXIX
IIIIIIIVVIXXIIXVIXXIXXLIV
IIIIIIIVVIXXIIXVIXXIXXLIVXLV
IIIIIIIVVIXXIIXVIXXIXXLIVXLVLXVIII
IIIIIIIVVIXXIIXVIXXIXXLIVXLVLXVIIILXXXIII
IIIIIIIVVIXXIIXVIXXIXXLIVXLVLXVIIILXXXIIIXCVII
IIIIIIIVVIXXIIXVIXXIXXLIVXLVLXVIIILXXXIIIXCVIIXCIX
IIIIIIIVVIXXIIXVIXXIXXLIVXLVLXVIIILXXXIIIXCVIIXCIXCD
IIIIIIIVVIXXIIXVIXXIXXLIVXLVLXVIIILXXXIIIXCVIIXCIXCDD
IIIIIIIVVIXXIIXVIXXIXXLIVXLVLXVIIILXXXIIIXCVIIXCIXCDDDI
IIIIIIIVVIXXIIXVIXXIXXLIVXLVLXVIIILXXXIIIXCVIIXCIXCDDDIDCXLIX
IIIIIIIVVIXXIIXVIXXIXXLIVXLVLXVIIILXXXIIIXCVIIXCIXCDDDIDCXLIXDCCXCVIII
IIIIIIIVVIXXIIXVIXXIXXLIVXLVLXVIIILXXXIIIXCVIIXCIXCDDDIDCXLIXDCCXCVIIIDCCCXCI
IIIIIIIVVIXXIIXVIXXIXXLIVXLVLXVIIILXXXIIIXCVIIXCIXCDDDIDCXLIXDCCXCVIIIDCCCXCIM
IIIIIIIVVIXXIIXVIXXIXXLIVXLVLXVIIILXXXIIIXCVIIXCIXCDDDIDCXLIXDCCXCVIIIDCCCXCIMMIV
IIIIIIIVVIXXIIXVIXXIXXLIVXLVLXVIIILXXXIIIXCVIIXCIXCDDDIDCXLIXDCCXCVIIIDCCCXCIMMIVMVI
IIIIIIIVVIXXIIXVIXXIXXLIVXLVLXVIIILXXXIIIXCVIIXCIXCDDDIDCXLIXDCCXCVIIIDCCCXCIMMIVMVIMXXIII
IIIIIIIVVIXXIIXVIXXIXXLIVXLVLXVIIILXXXIIIXCVIIXCIXCDDDIDCXLIXDCCXCVIIIDCCCXCIMMIVMVIMXXIIIMMXIV
IIIIIIIVVIXXIIXVIXXIXXLIVXLVLXVIIILXXXIIIXCVIIXCIXCDDDIDCXLIXDCCXCVIIIDCCCXCIMMIVMVIMXXIIIMMXIVMMMCMXCIX

Can you see what is going on?
This is what you should have got:

I
II
III
IV
V
IX
XII
XVI
XXIX
XLIV
XLV
LXVIII
LXXXIII
XCVII
XCIX
CD
D
DI
DCXLIX
DCCXCVIII
DCCCXCI
M
MIV
MVI
MXXIII
MMXIV
MMMCMXCIX

2 Likes

OOOOOOOUUU THANK YOUU VERY MUCH, i didn’t passed numbers one after one, now i will fix it!!!

1 Like

I passed the test, thank you so much !!!