Several simple calculators on one page For my students (I am an Austrian math teacher) I would like to provide some simple online calculators on my blog.
Let's say there are two pages on my website(&quot;Circle&quot; and &quot;Cube&quot;) and on every page I want to have about 10 different calculators.
Here is an example of one page with two calculators:

My code
JSFiddle
HTML
&lt;h1&gt;Circle&lt;/h1&gt;

&lt;h2&gt;Calculate circumference of circle&lt;/h2&gt;
&lt;p&gt;
 Radius of circle: &lt;input type=&quot;text&quot; id=&quot;calc1-input&quot;&gt; &lt;button onclick=&quot;calc1()&quot;&gt;Calculate&lt;/button&gt;
&lt;/p&gt;
&lt;p&gt;
Circumference of circle: &lt;span id=&quot;calc1-output&quot;&gt;&lt;/span&gt;
&lt;/p&gt;

&lt;h2&gt;Calculate area of circle&lt;/h2&gt;
&lt;p&gt;
 Radius of circle: &lt;input type=&quot;text&quot; id=&quot;calc2-input&quot;&gt; &lt;button onclick=&quot;calc2()&quot;&gt;Calculate&lt;/button&gt;
&lt;/p&gt;
&lt;p&gt;
Area of circle: &lt;span id=&quot;calc2-output&quot;&gt;&lt;/span&gt;
&lt;/p&gt;

Javascript
function commaToDot(number) {
    return parseFloat(number.replace(',','.').replace(' ',''));
}

function dotToComma(number){
    return number.toString().replace('.',',');
}

function calc1() {
    var input = document.getElementById(&quot;calc1-input&quot;).value;
    input = commaToDot(input);
    if (isNaN(input)) {
        document.getElementById('calc1-output').innerHTML = &quot;&lt;b&gt;Please enter a number!&lt;/b&gt;&quot;;
    } else {
      var output = 2 * Math.PI * input;
        document.getElementById('calc1-output').innerHTML = dotToComma(output);
    }
}

function calc2() {
    var input = document.getElementById(&quot;calc2-input&quot;).value;
    input = commaToDot(input);
    if (isNaN(input)) {
        document.getElementById('calc2-output').innerHTML = &quot;&lt;b&gt;Please enter a number!&lt;/b&gt;&quot;;
    } else {
      var output = Math.PI * Math.pow(input,2);
        document.getElementById('calc2-output').innerHTML = dotToComma(output);
    }
}

Explanation

Input: In my country we use commas as decimal separators.
So the students write 55,5 instead of 55.5 (see commaToDot()).
Output: The students expect the output to be with comma decimal separator, too (see dotToComma()).
Error: If the input is not a number (if (isNaN(input))) an error message will be displayed instead of the calculation result.

Questions

I see a lot of redundance in my code but I don't know how to improve it.
The only difference between calc1() and calc2() is the formula.
Maybe it is possible to improve the naming of the variables/functions?
calc1 and calc2 are really bad names. Names should always clearly describe what they are for or do. calculateCircleCircumference and calculateCircleArea would be better
choices.
I'm not a big fan of the names commaToDot and commaToDot either. I'd prefer more conceptional names such as parseNumber and formatNumber, maybe even parseGermanNumber and formatGermanNumber.
A slightly better HTML structure would be in order: Each calculator could be surrounded by a &lt;form&gt; element and there is an &lt;output&gt; element specifically for display calculation results.
In current JavaScript one should prefer const and let over var.
The following suggestions may introduce concepts, that the students haven't learnt yet, but they are considered good conventions.
For a better separation of layout and logic it is usually suggested not to use on... event handler attributes, but instead assign them using addEventListener.
Also one should move all element look ups to the initialization. This could look like this (notice the changed IDs):
const circleCircumferenceRadiusInput = document.getElementById(&quot;circle-circumference-radius-input&quot;);
const circleCircumferenceOutput = document.getElementById('circle-circumference-output');

function calculateCircleCircumference() {
    // Using separate variables so &quot;const&quot; can be used.
    const inputString = circleCircumferenceRadiusInput.value;
    const input = commaToDot(inputString);
    if (isNaN(input)) {
      circleCircumferenceOutput.innerHTML = &quot;&lt;b&gt;Please enter a number!&lt;/b&gt;&quot;;
    } else {
      const output = 2 * Math.PI * input;
      circleCircumferenceOutput.innerHTML = dotToComma(output);
    }
}

document.getElementById('circle-circumference-button').addEventHandler(&quot;click&quot;, calculateCircleCircumference);

This can be simplified a bit by wrapping HTML of the calculator in an &lt;form&gt; element and referring to the needed elements by name. Also I'm wrapping the code in an initialization function to avoid lots of global variables. Both of these prepare for generalizing and reusing the code.
&lt;form id=&quot;circle-circumference&quot;&gt;
  &lt;h2&gt;Calculate circumference of circle&lt;/h2&gt;
  &lt;p&gt;
    Radius of circle: &lt;input type=&quot;text&quot; name=&quot;radius&quot;&gt; &lt;button name=&quot;execute&quot;&gt;Calculate&lt;/button&gt;
  &lt;/p&gt;
  &lt;p&gt;
    Circumference of circle: &lt;output name=&quot;output&quot;&gt;&lt;/output&gt;
  &lt;/p&gt;
&lt;/form&gt;

function initCircleCircumferenceCalculator(form) {
  const radiusInput = form.elements[&quot;radius&quot;];
  const outputElement = form.elements[&quot;output&quot;];

  function calculate() {
    const inputString = radiusInput.value;
    const input = commaToDot(inputString);
    if (isNaN(input)) {
      outputElement.innerHTML = &quot;&lt;b&gt;Please enter a number!&lt;/b&gt;&quot;;
    } else {
      const output = 2 * Math.PI * input;
      outputElement.innerHTML = dotToComma(output);
    }
  }

  form.elements[&quot;execute&quot;].addEventHandler(&quot;click&quot;, calculate);
} 

initCircleCircumferenceCalculator(document.getElementById(&quot;circle-circumference&quot;));

Now that we have the initialization function it's easier to generalize this so that it can be used for multiple calculators:
function initCalculator(form, inputName, calculationFunction) {
  const inputElement = form.elements[inputName];
  const outputElement = form.elements[&quot;output&quot;];

  function calculate() {
    const inputString = inputElement.value;
    const input = commaToDot(inputString);
    if (isNaN(input)) {
      outputElement.innerHTML = &quot;&lt;b&gt;Please enter a number!&lt;/b&gt;&quot;;
    } else {
      const output = calculationFunction(input);
      outputElement.innerHTML = dotToComma(output);
    }
  }

  form.elements[&quot;execute&quot;].addEventHandler(&quot;click&quot;, calculate);
} 

// Circle circumference
initCalculator(document.getElementById(&quot;circle-circumference&quot;), &quot;radius&quot;, r =&gt; 2 * Math.PI * r);

// Circle area 
initCalculator(document.getElementById(&quot;circle-area&quot;), &quot;radius&quot;, r =&gt; Math.PI * Math.pow(r, 2));


The next step could be modify initCalculator so that it supports multiple input fields.