Exercise Tuesday

Goal: Practice gathering multiple pieces of information from corresponding sets of checkbox forms.


Transportation Survey

Similar to the site depicted in the previous lesson, create a website that prompts users to fill out a survey regarding which methods of transportation they've used to get to work in the past year. Include at least five options for users to select from.

Then, once you can successfully gather data from one question, include a second survey question asking users which methods of transportation they've used to travel to non-work or recreational activities. This second question should use a second set of checkboxes.

Quiz of Your Choice

Next, create a personality quiz that contains several questions that use checkboxes to select answers. Each question should instruct users to "Check all that apply".

A Stress Test

  • Include several questions.
    • One that lists warning signs of being negatively affected by stress ("Loss of sleep", "Feeling overwhelmed", etc.)
    • One that lists health symptoms linked to high-stress ("High blood pressure", "anxiety", etc.)
    • Another that lists recommended coping methods to deal with stress. ("Meditate", "Manage your time", "Pet a cat", etc.) Instruct users to check all that apply to them.
  • Then, based on user answers, provide some guidance: For instance, if a user reports 4 stress-related symptoms, and 6 warning signs apply to them, suggest some resources to help them out.
  • Or, if a user says 4 warning signs of high stress apply to them, but they also report using 5 of the recommended ways to manage stress, tell them they're doing a pretty good job.
  • Include at least 3 possible results.

A Fortune Teller Quiz

  • Similar to the project above, include a series of questions that instruct users to "Check all that apply".
  • Then, based on how many answers the users selected in each of several 'categories', provide them customized results.
  • For instance, you could prompt users to select each of the stereotypically "unlucky" events that have occurred to them in the last month ("Seeing a black cat", "Walking under a ladder", "Stubbing your toe", etc.), then how many "lucky" events have occurred ("Finding a four-leaf clover", "Seeing a rainbow", etc.) Then, based on this, provide them a silly fortune.
  • Include at least 3 possible results.

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.

Lesson 21 of 34
Last updated January 11, 2021