Skip to content Skip to sidebar Skip to footer

Simple Interval Not Clearing

I am building a game program with the following prompt: 'Modify Challenge #3 so that every time a player clicks the heading, instead of stopping, the heading speeds up, making it

Solution 1:

declare variable move outside instead of the inside handler function

var move;
$("#heading").click(function() {
  clearInterval(move);
  if (clicks < 10) {
    move = setInterval(moveHeading, speed -= 2);
    $("#heading").html(clicks + " Clicks!");
    clicks++;
  } else {
    $("#heading").html("You won!");
    $("#heading").css("color", "red");
    clearInterval(move);
  }
});

Post a Comment for "Simple Interval Not Clearing"