Chapter 7. Project: Electronic Life

“The question of whether Machines Can Think . . . is about as relevant as the question of whether Submarines Can Swim.”

Edsger Dijkstra, The Threats to Computing Science

In “project” chapters, I’ll stop pummeling you with new theory for a brief moment and instead work through a program with you. Theory is indispensable when learning to program, but it should also be accompanied by reading and understanding nontrivial programs.

Our project in this chapter is to build a virtual ecosystem, a little world populated with critters that move around and struggle for survival.


To make this task manageable, we will radically simplify the concept of a world. Namely, a world will be a two-dimensional grid where each ...

Get Eloquent JavaScript, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.