-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
76 lines (71 loc) · 1.75 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<html>
<head>
<title>Roman Numeral to Decimal</title>
<script type="text/javascript">
// <!--
var numeralChars = [
'I',
'V',
'X',
'L',
'C',
'D',
'M'
]
function convertNumerals() {
var current = 0
var previous = 0
for(var i = 0; i < numerals.value.length; i++) {
var character = numerals.value[i]
var index = numeralChars.indexOf(character)
if(index == -1) {
decimal.value = ''
return
}
var prefix = (index % 2) == 0 ? 1 : 5
var incoming = prefix * Math.pow(10, Math.ceil(index / 2))
if(index < previous) {
current -= incoming
} else {
current += incoming
}
}
decimal.value = current
}
/* from ChatGPT, basically the same with a few less safety checks
function romanToDecimal(roman) {
const romanToDecimal = {
I: 1,
V: 5,
X: 10,
L: 50,
C: 100,
D: 500,
M: 1000
};
let decimal = 0;
for (let i = 0; i < roman.length; i++) {
const current = romanToDecimal[roman[i]];
const next = romanToDecimal[roman[i + 1]];
if (next && current < next) {
decimal -= current;
} else {
decimal += current;
}
}
return decimal;
}
*/
// -->
</script>
</head>
<body>
<input type="text" id="numerals" name="numerals" value="MMXXIII" /><br />
<button onclick="convertNumerals()">Convert</button><br />
<input type="text" id="decimal" name="decimal" /><br />
<h1>Making this script</h1>
<script>
document.write(`<iframe width="560" height="315" allow="autoplay" modestbranding="true" src="https://www.youtube.com/embed/IZV-A5Y29mM&origin=\${window.location.origin}&controls=0&rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>`)
</script>
</body>
</html>