diff --git a/check.js b/check.js index 6ce2dc6..761480a 100644 --- a/check.js +++ b/check.js @@ -33,3 +33,4 @@ function check(){ } } setTimeout( function ( ) { alert( "Time is up!!!" ); location.reload();}, 300000 ) //added a timer to reset the gane after 5 mins + diff --git a/countdown.js b/countdown.js new file mode 100644 index 0000000..35f4865 --- /dev/null +++ b/countdown.js @@ -0,0 +1,53 @@ +function diff_easy(num) +{ startTimer(); + if(num==1){ + document.getElementById('timer').innerHTML = + 07 + ":" + 00;} + else{ + reset();} + } + +function diff_med(num) +{ startTimer(); + if(num==2){ + document.getElementById('timer').innerHTML = + 05 + ":" + 00;} + else{ + reset();} + } + +function diff_hard(num) + { startTimer(); + if(num==3){ + document.getElementById('timer').innerHTML = + 03 + ":" + 00;} + else{ + reset();} + } + +function reset(){ + window.location.reload(); +} + +function startTimer() { + var presentTime = document.getElementById('timer').innerHTML; + var timeArray = presentTime.split(/[:]+/); + var m = timeArray[0]; + var s = checkSecond((timeArray[1] - 1)); + if(s==59){m=m-1} + if(m<0){ + return + } + + document.getElementById('timer').innerHTML = + m + ":" + s; + console.log(m) + setTimeout(startTimer, 1000); + +} + +function checkSecond(sec) { + if (sec < 10 && sec >= 0) {sec = "0" + sec}; // add zero in front of numbers < 10 + if (sec < 0) {sec = "59"}; + return sec; +} \ No newline at end of file diff --git a/index.html b/index.html index bdc89ee..a1ec572 100644 --- a/index.html +++ b/index.html @@ -21,16 +21,28 @@ + + +
Choose "RESET" if you want to change the difficulty timer