Coin toss with JavaScript and HTML -
i need fixing script. basically, want flip coin , update <span>
result, i.e. if it's heads or tails. @ moment, nothing happens when click 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> got: <span id="result"></span> </p>
that's because need attach event handler:
document.getelementbyid('click').onclick = click; 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; };
<button id="click" type="button">click me</button> <p> got: <span id="result"></span> </p>
Comments
Post a Comment