Q:

clearInterval not working | undefined

I have such jQuery code and have problem with clearing intervals. 
    var secs = 50, width = 100; 
    var counter = function() {
    if(secs > 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);
});

Im trying to get this work for almost 5 hours without results. 
Both clearInterval(counter); and clearInterval(winner) are not working and flooding my server with requets. 
Thanks in advance for any help. 

A:

Let's see how you're clearing the interval. 
clearInterval(winner)

where, winner is the function.  To clear the interval, the ID of the interval should be passed as parameter. 
When setting the interval, catch the interval ID in a variable
winnerInterval = setInterval(winner, 3000);

and use this variable to clear interval. 
clearInterval(winnerInterval);

Make sure the variable containing interval ID is in the scope when clearing the interval. 
See clearInterval.