Comment

Comment by divbzero

I like superkuh’s suggestion to serve the spreadsheeets directly, so you don’t need to worry about converting the “calculators” to another language.

If you do want to go through the trouble of converting to another language, JavaScript would be the natural choice because it can run directly in the browser with just “a few static assets to host”. A template like the following would probably work fine as something simple and functional. (This should be a working example if you save the files to a directory and load foo.html in the browser.)

foo.js:

  function foo(a, b, c) {
    // do calculations and return output
    return a + b + c;
  }
foo.html:

  <!doctype html>
  <meta charset=utf-8>
  <title>Foo Calculator</title>
  <link rel=stylesheet href=https://cdn.simplecss.org/simple.css>
  
  <main>
    <h1>Foo Calculator</h1>
  
    <label for=a>A</label>
    <input type=number id=a>
  
    <label for=b>B</label>
    <input type=number id=b>
  
    <label for=c>C</label>
    <input type=number id=c>
  
    <label for=z>Z</label>
    <output id=z></output>
  </main>
  
  <script src=foo.js></script>
  
  <script>
    // calculate output when any input changes
    a.oninput = b.oninput = c.oninput = function () {
      z.value = foo(
        Number(a.value),
        Number(b.value),
        Number(c.value),
      ); 
    };
  </script>
a, b, c, z, and foo will be global variables in foo.html so make sure they have unique names.

simple.css could also be replaced with other classless CSS frameworks.

parent divbzero 4 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton