Simple Calculating

T

timw07

Not sure why I am not getting the approriate number here. I'm looking
to use square foot + 10% if number of stories = 1? Any and all help
for a newb is appreciated!

<script type="text/javascript">
function Calculate()
{
var realSquareFoot = SqFt.value;
var realStories = numStories.value;
var realPitch = pitch.value;

var calcSquareFoot


if (realStories == '1') {
var realPct = realSquareFoot * .1;
calcSquareFoot = realSquareFoot + realPct
alert(realSquareFoot);
alert(realPct);
alert(calcSquareFoot);
}


}

//------------------------
</script>

Square Footage:

<input id="SqFt" type="text" value=0> </input>
<br>

Number of Stories:

<select id=numStories>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
</select>

<br>
Pitch of Roof?
<select id=pitch>
<option value=1>Flat Roof</option>
<option value=2>Medium Steepness</option>
<option value=3>Very Steep</option>
</select>
<br>
<input type="button" onClick="Calculate()" value="Quote">
 
D

David Golightly

calcSquareFoot = +realSquareFoot + +realPct

That unary + is covered in the group FAQ.

Nothing to add, except to say that when using the unary +, I always
use parens since

+a + +b
and
+a + ++b
and
+a++ +b

aren't always easy for me to tell apart. Instead,

(+a) + (+b)

clearly shows the order of operation.

-David
 
T

timw07

Nothing to add, except to say that when using the unary +, I always
use parens since

+a + +b
and
+a + ++b
and
+a++ +b

aren't always easy for me to tell apart. Instead,

(+a) + (+b)

clearly shows the order of operation.

-David



Thanks David and Randy - truly helpful.
 
T

timw07

Nothing to add, except to say that when using the unary +, I always
use parens since

+a + +b
and
+a + ++b
and
+a++ +b

aren't always easy for me to tell apart. Instead,

(+a) + (+b)

clearly shows the order of operation.

-David



Thanks David and Randy - truly helpful.
 
D

Dr J R Stockton

In comp.lang.javascript message said:
That unary + is covered in the group FAQ.

But, as "unary" occurs nowhere in the FAQ, and "+" occurs 39 times, I'll
add that, while the OP should read the whole FAQ, unary + is in Section
4.21.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
oglegroups.com>, Thu, 23 Aug 2007 16:02:46, David Golightly
Nothing to add, except to say that when using the unary +, I always
use parens since

+a + +b
and
+a + ++b
and
+a++ +b

aren't always easy for me to tell apart. Instead,

(+a) + (+b)

clearly shows the order of operation.

Indeed; but I almost never need to use such parentheses. The OP has,
for example,
var realSquareFoot = SqFt.value;
which I would change to
var realSquareFoot = + SqFt.value;

The conversion to Number should be done only once, and it can best be
done when the value of a control is being transferred to a simple
variable.


P.S. I suspect that in your term +a++ the first + is not essential. Try
a = "1e4" ; x = a++ + 7 ; z = [a, x] ; // .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,883
Members
47,414
Latest member
djangoframe

Latest Threads

Top