Algarism to Roman

i Run this code that i made and its getting error but the code it’s working.
can someone help?

image

**Your code so far**
const convertion =
{
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 str ='';

function convertToRoman(num)
{
for(let i of Object.keys(convertion))
{
    let quo = Math.floor(num/convertion[i]);
    num=num - quo*convertion[i];
    str+=i.repeat(quo); 
}
String(str);
return str;


}
convertToRoman(3);
console.log(str)
**Your browser information:**

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

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

Link to the challenge:

Your code contains global variables that are changed each time the function is run. This means that after each function call completes, subsequent function calls start with the previous value. To fix this, make sure your function doesn’t change any global variables, and declare/assign variables within the function if they need to be changed.

Example:

var myGlobal = [1];
function returnGlobal(arg) {
  myGlobal.push(arg);
  return myGlobal;
} // unreliable - array gets longer each time the function is run

function returnLocal(arg) {
  var myLocal = [1];
  myLocal.push(arg);
  return myLocal;
} // reliable - always returns an array of length 2

It’s works putting the “str” inside the function but How can i see the Return Value ? because console.log didn’t recognize str because its a local variable;

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