добавил «щелкнул» вар, чтобы проверить, если время необходимо перезапустить
//---------------------------toggle-----------------------
$(".picture").click(function() {
$("#container").toggle("fold", 500);
});
$(".numbers1").click(function() {
$("#numbers").toggle();
});
//==========================================================
var done = true;
var clicked = true;
function check(counter){
if (counter >= 0) {
$("#count").text(counter);
}
if (counter === 0 && winner === 0) {
$("<div title='Oh no!'><center><img src='https://www.foreignlanguagesforkids.com/playa/images/shark.png'></center><p style='text-align: center;'>Let's get Calamity Carl to the hospital, pronto! Lucky for Carl, the doctors are experts at fixing him up and he will be as good as new in no time, only to get himself in trouble all over again!</p><div style='margin-top: 15px; width: 100%;'><div style='float: left; width: 48%; text-align; center;'><a class='btn button' href='https://www.foreignlanguagesforkids.com/playa'>Play Again</a></div><div style='float: right; width: 48%; text-align: center;'><a class='btn button' href='https://www.foreignlanguagesforkids.com/playa'>End Game</a></div><div style='clear: both;'></div></div></div>").dialog();
clearInterval(timer);
$('#fail')[0].play();
clicked = true;
}
}
$("#startClock").click(function() {
var counter = 60;
var winner = 0;
var winners=0;
//===============================================CAR DRAGGABLE===================
$("#car").draggable({
revert: "invalid", containment: "#wrapper",
start: function(event, ui){
if(!done) return false;
},
stop: function(event, ui){
if($(".correct").length == $(".drop").length){
setTimeout(function(){
$('#win').text(winner+' '+'stars'+' '+'earned');
},500);
winner = 1;
clearInterval(timer);
clicked = true;
}
}
});
$("#two").draggable({
revert: "invalid", containment: "#wrapper",
start: function(event, ui){
if(!done) return false;
},
stop: function(event, ui){
if($(".correct").length == $(".drop2").length){
setTimeout(function(){
$('#win1').text(winners+' '+'stars'+' '+'earned');
},500);
winners = 2;
clearInterval(timer);
clicked = true;
}
}
});
//===============================================/CAR DRAGGABLE End===================
//====================================================================Two draggable==========================
if(counter > 59 && clicked){
clicked = false;
timer = setInterval(function(){
check(counter);
counter--;
},1000);
}
//=========================================/TWO DRAGGABLE END==========================
});
//===================================================CAR DROPPABLE================================
$("#carDrop").droppable({
accept: "#car",
drop: function(event, ui) {
if(ui.draggable.is("#car")){
$(this).addClass("correct").find("p").html("correct!");
done = false;
ui.draggable.fadeOut(500);
$(this).fadeOut(500,function(){
done = true;
});
}
}
});
//==================================================two droppable===========================
$("#twoDrop").droppable({
accept: "#two",
drop2: function(event, ui) {
if(ui.draggable.is("#two")){
$(this).addClass("correct").find("p").html("correct!");
done = false;
ui.draggable.fadeOut(500);
$(this).fadeOut(500,function(){
done = true;
});
}
}
});
Пожалуйста, добавьте HTML и CSS, а также - JSFiddle был бы хорош – Thangaraja