ga-wdi-exercises / project1

[project] GA- Project 1
3 stars 75 forks source link

timer won't count down #188

Closed ghost closed 9 years ago

ghost commented 9 years ago

I can't seem to get the counter to countdown. I tried wrapping it all in a giant function and putting setInterval in the click function and nothing seems to get the count down to show.

$(document).ready(function(){
function createTimer(){
var counter = 5;
var timer = null;
var counterBox = function(){ $(".numberbox").html("counter:"+ ' '+counter )}

$("#button1").click(function(){
counterBox()
  })
  var timer = setInterval(function(){
   counter--;
  if (counter >= -1){
    counterBox.html("counter:"+ ' '+counter )
  }
    if (counter === 0)
      clearInterval(timer)

    else {clearInterval(timer)}

  }, 1000);
  };

createTimer()

});/*document end */
RobertAKARobin commented 9 years ago

Can you fix your indentation first? It's hard to read!