Hey.
A “num” should be equal to romanKeys. Roman keys is a massive (right?) so I have to turn it into a string to compare. But somehow it doesn’t work. What have I done wrongly?
Code:
function convertToRoman(num) {
var roman = {
1:'I',
2:'II',
3: 'III',
4: 'IV',
5: 'V',
6: 'VI',
7: 'VII',
8: 'VIII',
9: 'XI',
10: 'X'
};
var x;
var romanKeys = Object.keys(roman)[1].toString();
if (num === romanKeys) //this should be true
{return roman[1];}
else return false;
}
convertToRoman(2);
Thanks, that work!
But I have yet another problem - I can’t get info from the for loop (even if the loop isn’t actually “working”). Variable “x” stays empty for some reason. Could you pls take a look?
Code:
function convertToRoman(num) {
var roman = {
1:'I',
2:'II',
3: 'III',
4: 'IV',
5: 'V',
6: 'VI',
7: 'VII',
8: 'VIII',
9: 'XI',
10: 'X'
};
var x=[]; //this x should cointain roman[2], and it works without the for loop
for (var i=0;i<roman.length;i++){
var romanKeys = Object.keys(roman)[1];
if (num == romanKeys) {
x.push( roman[2]);
}
}
return x.toString();
}
convertToRoman(2);