previous

page 16

next
The Associative Array

The arrays we have been using are indexed by a number starting at zero whereas associative arrays are indexed by names.

I'm planning to use an associative array to define a turtle.
Add this to your my.js file then we'll study it.

function turtle (colr='black') {
var t={}; // associative array
t.colr=colr;
t.x=400; t.y=400; t.h=0;
t.width=2; t.pen='down';
return t;
}

Reload your page. Actually, this might be a good time to mention something very useful about the behind-the-scenes stuff. Provided you have that extra window open, you can hold down on the reload button:

Maybe you've noticed that the browser doesn't always recognise your latest changes - this is because it is using an older cached version of the changed file.

previous
next