JRS: In article <wZeee.1648$Vu.1318@trnddc07>, dated Thu, 5 May 2005
01:50:20, seen in news:comp.lang.javascript, David <ri***@dd.com> posted
:
It depends on how your calling the args. It will add the numbers correctly
if they are actual numbers so in your function call do not use any
quotations..
additionCalculator(10,20)
If you need to use quotations you'll have to parse the numbers because they
are considered as "text" and not actual numbers.
var total = parseInt(num1)+parseInt(num2);
additionCalculator('10','20')
You've only just arrived here; you need to look around a bit in order to
be sure of giving sound advice. Read the newsgroup FAQ, learn how to
format a news reply (Sec 2.3), learn why parseInt should only rarely be
used without a radix (4.12), and why it is not needed (4.21). See
signature.
"mwh" <a_********@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googleg roups.com... Hi.
...
var total = +num1 + +num2 // or = + num1 + + num2
will suffice. The + which are adjacent to the letter n can only be
unary-plus, the output of which is always a number.
Given that the inputs probably cone from a control, it's probably best
to "capture" them with lines like
var Num1 = + document ... Num1Input.value
and then work with Num1 - after reading the FAQ notes on Form Access
and/or Square Brackets.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.