Caesar plays Lottery
Write a method to convert a number between 1 and 50 to its Roman numeral equivalent.
(for example: 2 = ’II’, 10 = ’X’, 25 = ’XXV’, 50 = ’L’)
<html>
<body>
<script type="text/javascript">
function deromanize( roman ) {
var roman = roman.toUpperCase(),
lookup = {I:1,V:5,X:10,L:50,C:100,D:500,M:1000},
arabic = 0,
i = roman.length;
while (i--) {
if ( lookup[roman[i]] < lookup[roman[i+1]] )
arabic -= lookup[roman[i]];
else
arabic += lookup[roman[i]];
}
return arabic;
}
document.write(deromanize("VIII"));
</script>
</script></body>
</html>

No comments yet.