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:
- All roofs require 20 rows of
shingles. Each shingle is two feet long, so the number of shingles per
row will be 1/2 the width of the house (in feet).
- Nails come in coils of 1000.
You need 6 nails per shingle.
- All siding comes in 12 foot
lengths (assume they can be cut as needed to fill the space). Each
is 6 inches high. The number of lengths needed is based on the
width, depth, and height of the walls.
- Insulation sheets come in
standard 8 by 12 foot sheets (again, assume they can be cut as needed to
fill the space).
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:
- 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…).
- In the body, display a
welcome message like "Welcome Your Name's Homepage, Suppliers to
Roofing and Siding Contractors Since 2004."
- Write a JavaScript program
that does the following:
- 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.
- 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.)
- 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
- 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
|
- Where the __ indicates
where your computed values should go.
- Save the page as
your_name_exercise_2.html, test the page, and show your finished work to
either Sam or me.