Skip to content

Commit

Permalink
added logic for start/stop on same button
Browse files Browse the repository at this point in the history
  • Loading branch information
donyd committed May 27, 2017
1 parent 1bae938 commit 8f09f72
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ <h1>Stopwatch Demo</h1>
<p id="timer"></p>

<div class="buttons">
<button onclick="startStop(this)">Start</button>
<button onclick="startStop(this)">Stop</button>
<button onclick="stopStart(this)">Start</button>
<button onclick="stopStart(this)">Stop</button>
<button>Record Time</button>
<button>Reset Time</button>
</div>
Expand Down
24 changes: 24 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ function scriptCheck(){

var seconds = 0;
var startTimer;
var on = false;

function startStop(obj){
if (obj.innerHTML == "Start"){
Expand All @@ -16,3 +17,26 @@ function startStop(obj){
clearInterval(startTimer);
}
}



function stopStart(){
if(on == true){
clearInterval(startTimer);
on = false;
console.log(startTimer);
} else if (on == false){
startTimer = setInterval(function(){
seconds++;
document.getElementById("timer").innerHTML = seconds;}, 500);
on = true;
console.log(startTimer);
}

}






0 comments on commit 8f09f72

Please sign in to comment.