I’m trying to work out how to make this counter work. After a certain amount of animations have played, I want to make the page refresh. I know my code sucks. I’m not educated in this and I’m very new, not to mention it being difficult to concentrate (to say the least) where I’m staying at the moment… so be nice. Here it is:
$(document).ready(function () {
function loop() {
var p = 0;
if (p = 3) {
location.reload(true);
} else {
$("#p3").delay("1000").fadeIn("slow");
$("#p3").delay("1000").fadeOut("slow", loop);
p + 1;
};
loop();
});
Your
if (p = 3)statement is using the assignment operator=instead of the comparison operator===or==. Sopgets assigned to3, the result of which is truthy, so theelsestatement is never executed.Also your
pvariable is declared inside yourloop()function, so it gets reset every time the function is called – you could move that declaration to just before the function (keep it inside the document ready handler: no need to make it global).Also the line
p + 1;doesn’t do anything: it doesn’t incrementpbecause you’d need to assign the result back topwithp = p + 1, the shorthand for which isp += 1or justp++.Finally, your code as posted has a syntax error: you are missing the closing
}from theloop()function. I would guess the intention is to end the function and then call it, so: