JavaScript Algorithms and Data Structures Projects - Roman Numeral Converter

Freecodecamp keeps telling me TypeError: converter is not a function, when I go to solve this problem.

Your code so far

function convertToRoman(num) {
var converter = {
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,
};

var roman = "";

for (var key in converter){

while (num >= converter([key])){
 roman += key;
  num -= converter([key]);
} 
}

 return roman;
}

convertToRoman(36);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/117.0

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

Link to the challenge:

That’s because converter is not a function but you are treating it like a function here.

Note - var is a legacy feature and should not be used.

Thanks for your help. When you say " var is a legacy feature and should not be used." Can you explain ? If not var what should I have used ? “let” or “const” ?

Exactly!

1 Like

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