I am creating a program with css, html, and javascript. It needs to convert numbers to roman numerals. I can't seem to get any output. Can anyone give me suggestions?
Thanks!
javascript
Code:
Javascript
function convert(d) {
document.getElementById("output").innerText = value;
if (!+d){
alert('No data was input');
return '';
var digits = String(+d).split("");
key = ["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM",
"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC",
"","I","II","III","IV","V","VI","VII","VIII","IX"];
roman = "";
i = 3;
while (i--)
roman = (key[+digits.pop() + (i * 10)] || "") + roman;
return Array(+digits.join("") + 1).join("M") + roman;
}
html
Code:
....other code above
<body>
<div id="box">
<form>
<p>
CSE 3420.001<br/>
Program 3 - Javascript Application<br/>
Don Retzlaff donr@unt.edu
</p>
<input type="text" name="digit" id = "nums" value=""/>
<!-- <input type="submit" name="button" value="Convert to Roman Numerals" -->
<button onclick="convert(d)">convert to Roman Numerals</button>
</form>
<span id="output"></span>
</div>
</body>
.......other code below