3h of sleep and I cant figure this out... :S
I had a working something but I am changing the code a lot and removed it now I can not figure it back out. I really need help...
<!DOCTYPE html>
<html>
<body>
<p>Click the button to display a random number between 1 and 100.</p>
<button onclick="myFunction()">myFunction()</button>
<button onclick="myFunction2()">myFunction2()</button>
<p id="demo"></p>
<p id="demo2"></p>
<script>
var number = Math.floor((Math.random() * 100) + 1);
var number2 = 0;
function myFunction() {
number2 = Math.floor((Math.random() * 100) + 1);
var x = document.getElementById("demo")
x.innerHTML = number2;
}
//number2 is still 0.
function myFunction2() {
var x = document.getElementById("demo2")
x.innerHTML = number;
}
//number is stuck at the beginning number
</script>
</body>
</html>
I need to generate new numbers from the myFunction2. How do I achieve that ?
myFunction2generate a new number?myFunction2, notmyFunction