Exercise Monday

Further Exploration


A factorial is an operator that multiplies a number by all of the positive integers less than that number. For example, 5! = 5 * 4 * 3 * 2 * 1 = 120.

By definition, 0! = 1.

Make a web page to compute factorials. Do it without recursion, and then try it with recursion if you're up for a challenge. (Look online for info on recursion.)


A palindrome is any word, phrase, number, or other sequence of characters which reads the same backward or forward. Create a web page to identify whether or not a word is a palindrome.

Bonus points: Make your code check a string of words. For example: "Hello olleH" is a palindrome by our definition.

You may want to browse some of the built-in Javascript functionality available for strings and arrays.

Prime Sifting

Given a number, write a method that returns all of the prime numbers less than that number.

This is a tricky problem, and I want you to use the Sieve of Eratosthenes to solve it. Here's how the Sieve of Eratosthenes works to find a number up to a given number:

  • Create a list of numbers from 2 through n: 2, 3, 4, ..., number.
  • Initially, let prime equal 2, the first prime number.
  • Starting from prime, remove all multiples of prime from the list.
  • Increment prime by 1.
  • When you reach number, all the remaining numbers in the list are primes.

You also might find this video helpful in explaining the Sieve.

Now, implement this in JavaScript, using behavior examples to guide you. If you have time before class is over, make a website for a user to enter a number and return all of the prime numbers less than that number.