A. at the end of line 17 you have horizontal[fishPos[fishNumber] . That's a syntax error. You are missing a closing bracket after fishNumber .
B. On line 24 you have setInterval(fish1Swim, 100); , but there is no such thing as function fish1Swin(){...} declared anywhere, so I don't see how you can claim that you can make one fish swim (especially after the syntax error outlined on point A.). What you do have is function swimFish(){...} which expects a number, so what you need to do is call it once foreach of your fishes:
function startSwimming() {
setInterval("fishSwim(1)", 100);
setInterval("fishSwim(2)", 100);
setInterval("fishSwim(3)", 100);
}
c. fishPos is declared as number on line 9, but you are using it as an array in lines 17-20. Also, based on lines 18-20, it seems like you are "depending" on something like fishPos[1] for fish1, fishPos[2] for fish2, etc. So line 9 should be changed to an array where indices 1,2, and 3 are required to be initialized:
//the -1 is irrelevant. It's indices 1-3 that you need for fishPos[1]-fishPos[3].
var fishPos = [-1,0,0,0];
If you implement the changes above, you should see three fishes swimming in unison across the street. I'll leave it up to you to make them swim in different directions/rates.
hielo
Veteran Poster
1,131 posts since Dec 2007
Reputation Points: 116
Solved Threads: 247
Skill Endorsements: 0
Question Answered as of 2 Years Ago by
hielo