Any idea why this doesn't work?
function timeTankMove() {
var t=setTimeout("moveTank()",1000);
}
var direction = "right";
var amount = 0;
function moveTank() {
if (direction === "left" && amount<5) {
$(".tank").animate({"left": "-=70px"}, "slow");
amount += 1;
} else if (direction === "right" && amount<5) {
$(".tank").animate({"left": "+=70px"}, "slow");
amount += 1;
} else {
if (direction === "left") {
direction = right;
} else {
direction = left;
}
amount = 0;
}
$("p.debug").html(direction + " " + amount);
timeTankMove();
}
The tank moves to the right 5 times then stops, when it should be changing the direction to the opposite direction then reseting the count. Any idea why it's not working?
If you need me to, I can upload a version online or something.
Please excuse me if I made any ridiculous mistakes there. I'm not used to Javascript at all.