JavaScript Algorithms and Data Structures Projects - Roman Numeral Converter

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

Your code so far

function convertToRoman(num) {
let answer = "";
let pairs = {
  M:1000,
  CM: 900,
  D:500,
  CD:400,
  C:100,
  XC:90,
  L:50,
  XL:40,
  X:10,
  IX:9,
  V:5,
  IV:4,
  I:1,
}

let keys = Object.keys(pairs);
console.log(keys);
while(num > 0){
  let letter = "I"
  for(let i = 0; i<keys.length; i++){
    if(num >= pairs[keys[i]]){
      letter = keys[i];
      break;
    }
  }

  answer += letter;
  num = num - pairs[letter];

}

return answer;
}
}
console.(logconvertToRoman(44));

Your browser information:

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

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

Link to the challenge:

Your solution works. It only has two syntax errors. You have an unnecessary curly bracket, and your console.log syntax is also incorrect.
If you ident your code properly, it is much easier to read and helps to avoid little errors like this creeping in.

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