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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -