Javascript in class exercise #2


Throughout this assignment, where you see the phrase "Your Name", you should replace it with your own name when you write your program!

You are going to write a program for a company called Your Name's Building Suppliers.  This company provides roofing and siding supplies to meet the requirements of their customers, who are building contractors. Your JavaScript program will help your company determine what supplies a contractor needs to complete a roofing or siding job. Thrilling.

The program will make the following assumptions:

Roofing Jobs

A roofing job requires 2 types of supplies:  shingles and nails.

Siding Jobs

A siding job requires 2 types of supplies:  Lengths of siding, and sheets of insulation

You can assume that all supplies are of standard type, and no other supplies are needed.  Here are the rules to determine how much of each item is needed for each job:

At this point, we will assume that all houses are the same size: 40 feet wide by 25 feet deep by 30 feet high (to the top of the walls, not to the top of the roof).  Even though these numbers are constant, you must define variables for them and refer to the variables in all your calculations.  Calculate the total number of each type of supply needed, and output a summary on the page. Using HTML and JavaScript, do the following:

  1. Create an HTML document with a head, a title and a body. Make the title Your Name's JavaScript Exercise 2 (where "Your Name" must be replaced by your own, actual, first and last names…).
  2. In the body, display a welcome message like "Welcome Your Name's Homepage, Suppliers to Roofing and Siding Contractors Since 2004."
  3. Write a JavaScript program that does the following:
    1. Using the prompt() method, ask the user for the number of each type of job (roofing and siding). Save each of the answers in a separate variable. You will need to use a separate prompt for each value.
    2. When the user has entered all the data, use the confirm method to display the values entered, and ask the user if they are all OK. Use only a single confirm to display all the values! (You can’t assume the user will click OK so you need to write code to handle a case where the user clicks cancel instead of OK – this was covered in Dori’s lectures.)
    3. Calculate the amount of each component needed by taking the number of each type of job times the number of the supplies needed.  For example, if there are 3 siding jobs, and 4 roofing jobs, your program would compute:
      • number of roofing jobs * (number of rows * (shingles per row)) = 4*(20*(0.5*40)) = 1600 shingles
      • (number of nails per shingle * number of shingles) / (number of nails per coil) = ((6*1600) / 1000) = 9.6 coils of nails
      • number of siding jobs * (((2 * area of front wall) + (2 * area of side wall)) / (area of piece of siding)) = 3*(((2*40*30)+(2*25*30))/(12*0.5))= 1950 lengths of siding
      • number of siding jobs * (((2 * area of front wall) + (2 * area of side wall)) / (area of piece of insulation)) = 3*(((2*40*30)+(2*25*30))/(8*12))= 121.875 sheets of insulation

 

    1. Use the document.write method to display on the web page the results of the calculations. Your output should look like:

For __ roofing jobs and  __ siding jobs, you will need to order:
__ shingles
__ coils of nails
__ lengths of siding and
__ sheets of insulation

    1. Where the __ indicates where your computed values should go.
  1. Save the page as your_name_exercise_2.html, test the page, and show your finished work to either Sam or me.