JavaScript Algorithms and Data Structures Projects - Roman Numeral Converter

Tell us what’s happening:
Hey everyone, trying to understand what’s wrong with my code. I’ve tried placing some log messages and I’ve realized that the result variable is not getting updated. I haven’t completely finished the Javascript lessons yet, so maybe I’m missing some sort of super useful function, but could someone explain why my current code isn’t working?

Your code so far

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

Your browser information:

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

Challenge: JavaScript Algorithms and Data Structures Projects - Roman Numeral Converter

Link to the challenge:

i > arabic.length

Are you sure about that?

Wow. That’s what I get for coding while I’m tired

1 Like

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