From a57570558bcc26bc0b143a50863742a31ffd672c Mon Sep 17 00:00:00 2001 From: Christian Lawson-Perfect Date: Tue, 18 Mar 2025 15:42:42 +0000 Subject: [PATCH] first commit --- .make.lock | 0 index.html | 52 +++++++++++++++++++++++++++++++++++++++++++ script.js | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ style.css | 21 ++++++++++++++++++ 4 files changed, 138 insertions(+) create mode 100644 .make.lock create mode 100644 index.html create mode 100644 script.js create mode 100644 style.css diff --git a/.make.lock b/.make.lock new file mode 100644 index 0000000..e69de29 diff --git a/index.html b/index.html new file mode 100644 index 0000000..77d8b36 --- /dev/null +++ b/index.html @@ -0,0 +1,52 @@ + + + + + + Roman coin denomination converter + + + + +
+

Roman coin denomination converter

+
+
+
+ + + + + = + + + + + + + + +
+
+ + \ No newline at end of file diff --git a/script.js b/script.js new file mode 100644 index 0000000..29d84cb --- /dev/null +++ b/script.js @@ -0,0 +1,65 @@ +const form = document.getElementById('convert'); + +const values = { + 'Quadrans': 1, + 'Semis': 2, + 'As': 4, + 'Dupondius': 8, + 'Sestertius': 16, + 'Quinarius argenteus': 32, + 'Denarius': 64, + 'Quinarius aureus': 800, + 'Aureus': 1600, +} + +function gcd(a,b) { + if(a==0) { + return 1; + } + console.log(a,b); + if(a value_from ? [num_from, value_to/value_from] : [num_from * value_from/value_to, 1]; + const g = gcd(n,d); + n /= g; + d /= g; + const output = d==1 ? n : `${n} / ${d}`; + document.querySelector('output').textContent = output; +} + +function swap() { + const fd = new FormData(form); + const {num_from, from, to} = Object.fromEntries(Array.from(fd)); + + const value_from = values[from]; + const value_to = values[to]; + + document.getElementById('num_from').value = num_from * value_from/value_to; + + document.getElementById('from').value = to; + document.getElementById('to').value = from; + + update(); +} + +update(); + +form.addEventListener('input', update); + +document.getElementById('swap').addEventListener('click', swap); \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..438c4b1 --- /dev/null +++ b/style.css @@ -0,0 +1,21 @@ +:root { + --spacing: 1em; + + color-scheme: light dark; +} + +form { + display: flex; + gap: 1em; + text-align: center; + align-items: start; + +} +input { + text-align: center; +} + +.vertical { + display: inline-flex; + flex-direction: column; +} \ No newline at end of file