Bonfire 21: Roman Numeral Converter

TASK: Convert the given number into a roman numeral.

I confess I really struggled with this one. Looking around for hints I came across a few solutions that seem really clever and elegant, like this one, or this one. Claiming that I fully understand them would be a bit of a stretch, but here we go:

var lookup = {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 numeral = '';

for (var i in lookup) {
while (num >= lookup[i]) {
numeral += i;
num -= lookup[i];
return numeral;

Bonfire 21: Roman Numeral Converter

One thought on “Bonfire 21: Roman Numeral Converter

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s