I am new to javascript and jquery, so, as a challenge, I am doing little game and ran into the problem today.
So, the code works like: there appears some text and after some time it needs to fadeOut
, but it just won't fadeOut
for me...
Here's my code:
var timeToStart = 3;
var timer = 0;
function count() {
document.getElementById("gameStarter").innerHTML = timeToStart + " s";
timeToStart = timeToStart - 1;
}
$("#start").click(function() {
$("#gameStart").fadeIn(500, function() {
timer = setInterval(count, 1000);
setTimeout(function() {clearInterval(timer);}, 4000);
if (timeToStart == 0) {
$("#gameStart").fadeOut(500)
}
});
});