<!DOCTYPE html>
<html lang="de">

<head>
  <meta charset="utf-8">
  <title>Aufg 5: Plus Minus</title>
  <link rel="stylesheet" href="js4.css">

</head>

<body>
  <form>
    <p><input id="idAddition" name="operation" type="radio" value="Addition" checked="checked">Plus
      <input id="idSubtraktion" name="operation" type="radio" value="Subtraktion">Minus
      <input id="idMultiplikation" name="operation" type="radio" value="Multiplikation">Mal
      <input id="idDivision" name="operation" type="radio" value="Division">Geteilt
    </p>

    <p><input id="idEingabe1"> Erste Zahl</p>
    <p><input id="idEingabe2"> Zweite Zahl</p>
    <p><input id="idRechnen" type="button" value="Rechnen"></p>
    <p id="info"></p>
    <p><input id="idAusgabe" disabled> Ausgabe</p>
  </form>

  <script>
    const r1 = document.getElementById("idAddition");
    const r2 = document.getElementById("idSubtraktion");
    const r3 = document.getElementById("idMultiplikation");
    const r4 = document.getElementById("idDivision");
    const eingabe1 = document.getElementById("idEingabe1");
    const eingabe2 = document.getElementById("idEingabe2");
    const ausgabe = document.getElementById("idAusgabe");
    const re = document.getElementById("idRechnen");
    re.addEventListener("click", rechnen);

    function rechnen() {
      let tx;
      if (r1.checked) tx = r1.value;
      else if (r2.checked) tx = r2.value;
      else if (r3.checked) tx = r3.value;
      else if (r4.checked) tx = r4.value;
      let zahl1, zahl2;
      if (eingabe1.value == "" || isNaN(eingabe1.value))
        zahl1 = 0;
      else
        zahl1 = parseFloat(eingabe1.value);
      if (eingabe2.value == "" || isNaN(eingabe2.value))
        zahl2 = 0;
      else
        zahl2 = parseFloat(eingabe2.value);
      if (tx == "Addition") ausgabe.value = zahl1 + zahl2;
      else if (tx == "Subtraktion") ausgabe.value = zahl1 - zahl2;
      else if (tx == "Multiplikation") ausgabe.value = zahl1 * zahl2;
      else if (tx == "Division") ausgabe.value = zahl1 / zahl2;
      var inf = document.getElementById("info");
      if (ausgabe.value >= 0) {
        inf.innerHTML = "Das Ergebnis ist positiv.";
      } else {
        inf.innerHTML = "Das Ergebnis ist negativ.";
      }
    }
  </script>

</body>

</html>            
         
            
                           
        
            
                           
         

External Javascript and CSS