I’m trying to create a program with Javascript that prints two random numbers and calculates their sum. It should be really easy, but for some reason I can’t get the program to work. I’ve got the program to print random numbers, but I can’t get it to add the numbers together. What am I doing wrong?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<p id="myBtn"></p>
<p id="number1"></p>
<p id="number2"></p>
<button id="myBtn" onclick="myFunction()">Get random number</button>
<script>
var allNumbers = 0;
function myFunction() {
num1 = document.getElementById("number1").innerHTML = Math.floor(Math.random() * (7 - 1) + 1);
num2 = document.getElementById("number2").innerHTML = Math.floor(Math.random() * (7 - 1) + 1);
var inTotal = num1 + num2;
var allNumbers =+ inTotal;
}
document.write(allNumbers);
</script>
</body>
</html>