Now it's time to tackle the interesting stuff!

First there's the animation - you may like to check out the demo on page 1 again.

Basically we want to do one forward step and then pause. But how will we know when it's time to make a right turn? And how will we know when it's time to stop?

Obviously we'll need to keep track of where we are.

Referring back to your test, you should see that we need to keep track of the i, j and k counters.

So I propose the following globals - g_i, g_j and g_k all initialised to zero.

function one_step() {
  fd(); g_k++;
  if (g_k==g_numbers[g_j]) {
    g_j++; g_k=0; rt();
  }
  if (g_j==5) {
    g_i++; g_j=0
  }
  if (g_i<4) setTimeout(one_step,200);
}

Makes you realise how great the JavaScript for statement is, eh?