This will start the timer after the first press:
var timer; document.getElementById( 'game' ).onclick = function(){ timer = setInterval(function () { document.getElementById("seconds").innerHTML = pad(++sec % 60); document.getElementById("minutes").innerHTML = pad(parseInt(sec / 60, 10)); }, 1000); this.onclick = null; };
This is the html that you provided to trigger character selection:
<div id="pickerButton"> <h2>Pick o or x</h2> <button class="pickerButton" type="button">X</button> <button class="pickerButton" type="button">O</button> </div>
Add this somewhere inside the Game
function:
var buttons = document.getElementsByClassName( 'pickerButton' ); buttons[0].onclick = function(){ var context = { 'player1' : 'x', 'player2' : 'o' }; this.parentNode.style.display = 'none'; }; buttons[1].onclick = function(){ var context = { 'player1' : 'o', 'player2' : 'x' }; this.parentNode.style.display = 'none'; };
Edit: merged everything together - https://jsfiddle.net/ftfuh1oj/
source share