<html>
  <head>
    <title>JS Rechentrainer</title>
   <script src="code.js"></script>
  </head>
  <body>
    <h3>Rechentrainer</h3>
      <p id="task">Hier erscheint die Aufgabe</p>
    <button id="ans1" onclick="proof(this)" type="button">Antwort1</button>
    <button id="ans2" onclick="proof(this)" type="button">Antwort2</button>
    <button id="ans3" onclick="proof(this)" type="button">Antwort3</button>
  </body>
</html>
var task; //task as text
var num1, num2;
var a, b, c;

window.onload = function newTask(){
    num1 = 5;
    num2 = 6;
    task = ""+num1+"+"+num2;
    b = num1 + num2;
    a = b - 1;
    c = b + 1;
    document.getElementById('task').innerHTML = task;
    document.getElementById('ans1').innerHTML = a;
    document.getElementById('ans2').innerHTML = b;
    document.getElementById('ans3').innerHTML = c;
}

function proof(button){
  var val = button.textContent || button.innerText;
  if(val == num1+num2){
  button.style.background='green';
     }
  else{
    button.style.background='red';
  } 
}
Rerun