Drag your mouse in the direction of the apples to eat them all!
I got most of the code from "Code Your Own Games!" by Max Wainewright.