It works fine (for me at least) until I try to translate English letters into Roman Numerals.
I want to to translate "18" into "XVII" and "1212" into "MCCXII". Also, is there a way it can still translate "1,212" into "MCCXII"?
Here's all the code:
<html>
<head>
<link rel="icon" href="http://claof.com/ClaofIcon.ico?v=2"></link/>
<title>English to Latin</title>
<body bgcolor="lightgray">
<center><input style="text-align:center;width:100%" placeholder="English text..." id="english"></input><br>
<a id="latin"></a></center>
</body>
<script>
xx=0
function replace_text() {
document.getElementById('english').value = document.getElementById('english').value.toUpperCase()
str = document.getElementById('english').value.toLowerCase()
if (document.getElementById('english').value.length) {
for (i=100000;i>0;i--) {
number = document.getElementById('english').value.match(/\d+/)[0]
v=i
v.toString()
if (number.match(v)) {
xx = toRoman(number.match(v))
}
}
}
str = str.split("").reverse().join("")
str = str.replace(/a/g, "");
str = str.replace(/b/g, "");
str = str.replace(/c/g, "");
str = str.replace(/d/g, "");
str = str.replace(/e/g, "");
str = str.replace(/f/g, "");
str = str.replace(/g/g, "G");
str = str.replace(/z/g, "");
str = str.replace(/h/g, "");
str = str.replace(/i/g, "");
str = str.replace(/j/g, "");
str = str.replace(/k/g, "");
str = str.replace(/l/g, "");
str = str.replace(/m/g, "");
str = str.replace(/n/g, "");
str = str.replace(/o/g, "");
str = str.replace(/p/g, "");
str = str.replace(/q/g, "");
str = str.replace(/r/g, "");
str = str.replace(/s/g, "");
str = str.replace(/t/g, "");
str = str.replace(/v/g, "");
str = str.replace(/w/g, "");
str = str.replace(/x/g, "");
str = str.replace(/y/g, "Y");
str = str.replace(/u/g, "");
document.getElementById('latin').innerHTML = str
}
setInterval("replace_text()",0)
function toRoman(num) {
var result = '';
var decimal = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
var roman = ["M", "CM","D","CD","C", "XC", "L", "XL", "X","IX","V","IV","I"];
for (var i = 0;i<=decimal.length;i++) {
// looping over every element of our arrays
while (num%decimal[i] < num) {
// keep trying the same number until it won't fit anymore
result += roman[i];
// add the matching roman number to our result string
num -= decimal[i];
// remove the decimal value of the roman number from our number
}
}
return result;
}
</script>
</head>
</html>
And