Roman Numeral Converter confusion

Tell us what’s happening:
This code works, but originally only have of the cases were working. That was because I didn’t use the hints advice of adding in values like 900, 400, etc… I don’t understand why adding those values changes anything. Can someone explain the logical process of why those values are necessary to make the code function?

Your code so far

function convertToRoman(num) {
  let roman = [ 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I' ];
  let decimal = [ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 ];
  let romStr = '';
  for(let i=0;i<roman.length; i++){
      romStr += roman[i];
      num -= decimal[i];
 return romStr;


Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS aarch64 11151.29.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.49 Safari/537.36.

Link to the challenge:

It’s because those values are exceptions to the general pattern Roman numerals are written by. Normally a Roman numeral is written as a sequence of smaller ones, starting from the largest. But for numbers on the upper boundary of a given range, like 4, 9, or 900, that proves a bit cumbersome (900 would be written as DCCCC). So, for those numbers, ancient Romans wrote the letter representing the next range, preceded by smaller numeral, e.g. IV is “one less than 5”. Written this way, 900 becomes CM, or “100 less than 1000”. Hope that helps.

That clears it up! thanks!