Exercise : Turtles All the Way Down


A well-known scientist (some say it was Bertrand Russell) once gave a public lecture on astronomy. He described how the earth orbits around the sun and how the sun, in turn, orbits around the center of a vast collection of stars called our galaxy. At the end of the lecture, a little old lady at the back of the room got up and said: What you have told us is rubbish. The world is really a flat plate supported on the back of a giant tortoise. The scientist gave a superior smile before replying, What is the tortoise standing on? You're very clever, young man, very clever, said the old lady. But it's turtles all the way down!

Stephen Hawking, A Brief History of Time

(see also: Turtles all the way down on Wikipedia)

Exercise : Turtles All the Way Down


Exercise : Implementation Details / Hints

Use these events and properties to help you implement your solution:

An event that occurs when the user moves the scrollbar.
The height of the entire web page.
The number of pixels that we have currently scrolled down from the top of the page.
The height of the visible area of the page currently on-screen.

Exercise Solution

window.onload = function() {
	document.onscroll = turtles;
	turtles(); // in case window height is initially taller than animals

function turtles() {
	while (window.scrollY + window.innerHeight >= document.body.scrollHeight) {
		var div = document.createElement("div");
		div.className = "turtle";