Here is the code, the function occurs when an img is clicked via the code below.
onclick="rollDice();"
The function calls upon the Element "rollResult" which then becomes the... well... result.
<h2 id="rollResult"></h2>
This is Paragraph that I would like to become the bearer of good or bad news.
<p2 id="winOrLose"></p2>
Below is the function executed upon clicking the img, it calls upon the rollResult element when defined as the variable "x" which I then go on to compare in an 'if' statement to the number 70. If result of the roll is greater than 70 you have won any other roll below 70 is a loss.
function rollDice() {
var x = document.getElementById("rollResult");
x.innerHTML = Math.floor((Math.random() * 100) + 1);
if (x > 70) {
resultFinal = "You've won.";
} else {
resultFinal = "You lose.";
}
document.getElementById("winOrLose").innerHTML = resultFinal;
}
However, when tested the button works fine issuing for a random number to be generated and one is displayed however the message of "You've won." or "You lose." is always "You lose." regardless of how many times I generate a number, something is wrong with my 'if' statement I think.
Can anyone help?