Thread: Function for Computing Square Feet and Yard

1. Registered User
Join Date
Nov 2012
Posts
16

Function for Computing Square Feet and Yard

I need to write a function for computing square feet and one for yards that:
-gets the values for length, width, and overage
-computes the correct number of square feet needed
-sets the value of the appropriate form input area
-Performs a document.write to display the results on a new html page
I have absolutely no experience with javascript so i don't even know where to begin

2. Registered User
Join Date
Nov 2012
Posts
16
Forgot to add that this is part of an html page for calculating how much carpet a person will need, and there is an extra variable for how much extra should be used. the exact quote from the site is
"Typically an allowance is made for room irregularities and unavoidable waste.
Enter the percent overage as an integer in the interval [0, 20]"

3. Registered User
Join Date
Nov 2012
Posts
16
anyone? :'( lmao

4. Originally Posted by guero311
I need to write a function for computing square feet and one for yards that:
..........
I have absolutely no experience with javascript so i don't even know where to begin
A trip to a bookstore to pick up a good primer on JavaScript would be a good place to start unless you are in class and already have a good textbook.

This is an example of a simple page which crunches some numbers from a form and writes a new html page if the user asks for it: mortgage.htm. View the source to get ideas on reading data from a form, etc.

The way this forum is normally used is someone says, "I've done this, this, this, and this but I can't figure out how to do this. This is what I have so far. {Gives examples} Thanks in advance."

5. Registered User
Join Date
Nov 2012
Posts
16
Originally Posted by wbport
A trip to a bookstore to pick up a good primer on JavaScript would be a good place to start unless you are in class and already have a good textbook.

This is an example of a simple page which crunches some numbers from a form and writes a new html page if the user asks for it: mortgage.htm. View the source to get ideas on reading data from a form, etc.

The way this forum is normally used is someone says, "I've done this, this, this, and this but I can't figure out how to do this. This is what I have so far. {Gives examples} Thanks in advance."
i'm in a class but the textbook isn't helping me understand the way it works. normally i would have some examples of what i've got finished, but the only thing i have to do is write those 2 functions and i have no clue how they work lol. unfortunately our teacher never actually teaches class and instead gets up and talks about whatever random crap is on his mind for the day. it was fine for html since i was able to pick it up and make sense of it all, but java isn't going so well

6. Registered User
Join Date
Mar 2009
Posts
452
this can be a good example for you, check their source to get an idea, http://www.onlineconversion.com/area.htm

7. Registered User
Join Date
Nov 2012
Posts
16
yea i was looking at the code and it kind of helps. it's definitely a good example. i just gotta figure out what everything means! lol. it looks so much like visual basic to me that it's kinda confusing

8. Registered User
Join Date
Oct 2010
Location
Versailles, France
Posts
1,290
Do not use Feet and Yard which are depreciated... Use the International System of Units !

9. How would you do the problem with pencil, paper, and a calculator? Probably something like

Answer = length * width * (1 + overage/100)

You will be doing that same calculation in JavaScript. Verify that overage is in range (else alert()) and is an integer, crunch the numbers, and display the answer.

That mortgage example was close to the first thing I ever did, being near the front of a primer I read a few years ago, so it can't be that hard to grasp. I've since added an option for number of months, a new PI popup window, and a "Last Modified" script, but that was originally copied verbatim from the book.

BTW, does this problem have a form or does it get its data from prompts?

10. Registered User
Join Date
Nov 2012
Posts
16
Originally Posted by wbport
How would you do the problem with pencil, paper, and a calculator? Probably something like

Answer = length * width * (1 + overage/100)

You will be doing that same calculation in JavaScript. Verify that overage is in range (else alert()) and is an integer, crunch the numbers, and display the answer.

That mortgage example was close to the first thing I ever did, being near the front of a primer I read a few years ago, so it can't be that hard to grasp. I've since added an option for number of months, a new PI popup window, and a "Last Modified" script, but that was originally copied verbatim from the book.

BTW, does this problem have a form or does it get its data from prompts?
it's just a simple form with buttons. i already know this all should be easy but unfortunately my textbook does a poor job of explaining how things work and only over-complicates everything. i actually found a script that does the feet calculations on the internet, but i don't want to use something i don't fully understand you know?

11. Registered User
Join Date
Nov 2012
Posts
16
so i just read the entire chapter that deals with this assignment and it left out a ton of info that i need. i know that data is pulled from the input area in the format of var x= example.area.value, but i'm not sure where the area actually is. here's the body of the page this goes to
HTML Code:
```<body>

<h1>Carpet Calculator</h1>

<form name = "carpet" action=" ">

</br>Enter the length of your room in feet</br><input name = "length" type = "text" />

</br>Enter the width of your room in feet</br><input name = "width" type = "text" />
</br>Typically an allowance is made for room irregularities and unavoidable waste.
</br>Enter the percent overage as an integer in the interval [0, 20]</br><input name = "overage" type = "text" />

</br></br><input name = "SqFt" type = "button" value = "Compute Square Feet   " onclick = "ComputeSquareFeet()" />

</br></br><input name = "SqYd" type = "button" value = "Compute Square Yards" onclick = "ComputeSquareYards()" />

</br></br><input type = "reset" value = "Clear" />

</form>

</body>```

12. You see there is a form involved. In the mortgage page, was that form referenced when reading the value the user entered? What do you see instead of example on my page?

13. Registered User
Join Date
Nov 2012
Posts
16
Originally Posted by wbport
You see there is a form involved. In the mortgage page, was that form referenced when reading the value the user entered? What do you see instead of example on my page?
i see you used "document.loandata.principal.value;" and loandata was the name of the form so i guess where you have that, i would put carpet for mine? would it be document.carpet.length.value?

14. Originally Posted by guero311
i see you used "document.loandata.principal.value;" and loandata was the name of the form so i guess where you have that, i would put carpet for mine? would it be document.carpet.length.value?
Ding Ding Ding Ding Ding Ding Ding Ding! We have a winner!!

15. Registered User
Join Date
Nov 2012
Posts
16
Originally Posted by wbport
Ding Ding Ding Ding Ding Ding Ding Ding! We have a winner!!
awesome, now we're gettin somewhere! ok so i think i'll be able to get the calculations part when i get a chance to work on it. my last question for now is about the last requirement of the function. it says to use document.write to display the results on a new html page. what code would i use for that? or is that just default what happens when you use document.write?