I have the following function that counts and outputs the order number for every item within a div:
$('.number').each(function(i) {
$(this).text(++i);
$(this).text(function (i, n) {
var result = Number(n) + 0;
return result;
});
});
I'm trying to turn the numbers into Roman letters and I've tried the following, without success:
function convertToRoman(num) {
var roman = {
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 str = '';
for (var i of Object.keys(roman)) {
var q = Math.floor(num / roman[i]);
num -= q * roman[i];
str += i.repeat(q);
}
return str;
}
Would it be a way to do that?