title: clearInterval not working | undefined
body: <p>I have such jQuery code and have problem with clearing intervals.</p>
  
  <pre><code>    var secs = 50, width = 100; 
      var counter = function() {
      if(secs &gt; 0) {
          secs--;
          width = width - 2;
          $('#time').css('width', width + '%').attr('aria-valuenow', width);
          $('.seconds').html(secs);
      } else if(secs == 0){
          $('.questions').addClass('hidden');
          $('.results').removeClass('hidden');
          clearInterval(counter);
          setInterval(winner, 3000);
      }
  };
  var winner = function() {   
      $.ajax({
          type: "POST",
          url: "ajax.php",
          data: {
              func: "game_results"
          },
  
          error: function() {
              swal("Błąd", "Serwer nie odpowiada, spróbuj ponownie", "error")
          },
          success: function(data) {
  
              if (data == "you") {
                  $('.waiting').addClass('hidden');
                  $('.you').removeClass('hidden');                    
              } else if (data == "opponent") {
                  $('.waiting').addClass('hidden');
                  $('.opponent').removeClass('hidden');               
              }
          }
      });
      console.log(clearInterval(winner)); // heer
  }
  
  function answer(question_id, answer, question) {
      var question_higher = question_id + 1;
  
      $.ajax({
          type: "POST",
          url: "ajax.php",
          data: {
              func: "play",
              answer: answer,
              question: question
          },
  
          error: function() {
              swal("Błąd", "Serwer nie odpowiada, spróbuj ponownie", "error")
          },
          success: function(data) {
  
              if (data == "wrong") {
                  $.playSound('build/sounds/wrong');
                  $('*[data-question="' + question_id + '"]').find('.' + answer + '').removeClass('btn-primary').addClass('btn-danger');
                  $('*[data-question="' + question_id + '"]').find('.col-sm-12').addClass('dimmed');
                  setTimeout(function() {
                      $('*[data-question="' + question_id + '"]').addClass('hidden');
                      $('*[data-question="' + question_higher + '"]').removeClass('hidden');
                  }, 750);
              } else if (data == "correct") {
                  $.playSound('build/sounds/correct');
                  $('*[data-question="' + question_id + '"]').find('.' + answer + '').removeClass('btn-primary').addClass('btn-success');
                  $('*[data-question="' + question_id + '"]').find('.col-sm-12').addClass('dimmed');
                  setTimeout(function() {
                      $('*[data-question="' + question_id + '"]').addClass('hidden');
                      $('*[data-question="' + question_higher + '"]').removeClass('hidden');
                  }, 750);
              }
          }
      });
  
      if(question_id == 5) {
          clearInterval(counter);
          setTimeout(function() {
          //$('.questions').addClass('hidden');
          $('.results').removeClass('hidden');
          }, 750);
          setInterval(winner, 3000);      
      }
  
  }
  
  $(document).ready(function() {
      $('*[data-question="1"]').removeClass('hidden');
      setInterval(counter, 1000);
  });
  </code></pre>
  
  <p>Im trying to get this work for almost 5 hours without results.
  Both <code>clearInterval(counter);</code> and <code>clearInterval(winner)</code> are not working and flooding my server with requets.
  Thanks in advance for any help.</p>