When I try to run this program, I get an error in Firefox saying that:
moveDate is undefined on line 41
(referring to the line window.setTimeout("moveDate()",100);.
Any ideas why? I thought recursive functions were able to define themselves and then call upon themselves.
function monthScroller(){
document.getElementById("month").style.visibility = "visible";
var x = 0;
var y = 0;
var dest_x = window.innerWidth/2;
var dest_y = window.innerHeight/2;
var interval = 1;
function moveDate() {
if(x<dest_x){ x = x + interval;}
if(y<dest_y){ y = y + interval;}
document.getElementById("month").style.top = y+"px";
document.getElementById("month").style.left = x+"px";
if ((x+interval < dest_x) && (y+interval < dest_y)) {
window.setTimeout("moveDate()",100);
}
else{
name();
}
}
moveDate();
}
Yes, they are. Yet,
window.setTimeout("moveDate()",100);will eval that code string in the global scope – nomoveDateto be found there. Instead, pass the function reference tosetTimout():