let leftOff = 0,
topOff = 0,
amount = 0,
speed = 200;
function move(){
if(leftOff < 200 && topOff <= 0){
$('#one').offset({
left: leftOff++
});
}else if(leftOff >= 200 && topOff < 200){
$('#one').offset({
top: topOff++
});
}else if(leftOff > 0 && topOff >= 200){
$('#one').offset({
left: leftOff--
});
}else if(leftOff <= 0 && topOff > 0){
$('#one').offset({
top: topOff--
});
}
}
setInterval(move, speed);
$('#one').click(function(event){
if(amount === 10){
clearInterval(1);
$('#one').text('Вы выиграли');
return;
}else{
speed -= 10;
amount++;
clearInterval(1);
setInterval(move, speed);
$('#one').text(amount);
}
});
clearInterval(1);
let leftOff = 0,
topOff = 0,
amount = 0,
speed = 200,
intervalId;
function move(){
if(leftOff < 200 && topOff <= 0){
$('#one').offset({
left: leftOff++
});
}else if(leftOff >= 200 && topOff < 200){
$('#one').offset({
top: topOff++
});
}else if(leftOff > 0 && topOff >= 200){
$('#one').offset({
left: leftOff--
});
}else if(leftOff <= 0 && topOff > 0){
$('#one').offset({
top: topOff--
});
}
}
intervalId = setInterval(move, speed);
$('#one').click(function(event){
if(amount === 10){
clearInterval(intervalId);
$('#one').text('Вы выиграли');
return;
}else{
speed -= 10;
amount++;
clearInterval(intervalId);
intervalId = setInterval(move, speed);
$('#one').text(amount);
}
});