26
rated 0 times
[
33]
[
7]
/ answers: 1 / hits: 31792
/ 9 Years ago, sun, august 30, 2015, 12:00:00
I need help fixing my script. Basically, I want it to flip a coin and update a <span>
with the result, i.e. if it's heads or tails. At the moment, nothing happens when I click the button.
JavaSript:
var heads = 0;
var tails = 0;
function click() {
x = (Math.floor(Math.random() * 2) == 0);
if(x){
flip(heads);
}else{
flip(tails);
}
};
function flip(coin) {
document.getElementById(result).innerHTML = coin;
};
HTML:
<button id=click type=button>CLICK ME</button>
<p>
You got: <span id=result></span>
</p>
More From » html