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’)

Coding Kata

<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>	

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>