Thread: Basic Javascript question
-
March 22nd, 2011, 02:01 PM #1Junior Member
- Join Date
- Feb 2011
- Posts
- 6
Basic Javascript question
I want to take three values in from the user and perform various basic mathematical operations on them.
I am taking input like this:
var firstnumber = prompt("blah blah...
var secondnumber = prompt("blah blah...
and then adding them together like this
var result = firstnumber+secondnumber
However this just concatenates the values as if they were strings, e.g. if you entered "7" and "3" instead of getting 10 you get 73!
I know how to add them if I hard-coded the variables, but I want the user to input them.
-
March 22nd, 2011, 02:24 PM #2Junior Member
- Join Date
- Feb 2011
- Posts
- 6
I ended up just doing:
firstnumber = firstnumber*1 to force it as a numerical value. Not sure if that's best practise?
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Basic javascript help with if function
By fefefasesdfs in forum Webmastering and ProgrammingReplies: 2Last Post: August 8th, 2010, 10:29 AM -
basic Javascript question -- GetElementByID
By Olvie in forum Webmastering and ProgrammingReplies: 0Last Post: April 16th, 2009, 02:40 PM -
Very basic Javascript question
By flutter in forum Webmastering and ProgrammingReplies: 5Last Post: February 27th, 2009, 11:36 AM -
Beginner Javascript question
By James Engle in forum Webmastering and ProgrammingReplies: 0Last Post: April 21st, 2008, 10:43 PM -
Quick javascript question
By NineOne in forum Webmastering and ProgrammingReplies: 2Last Post: November 5th, 2002, 12:35 AM



LinkBack URL
About LinkBacks



Reply With Quote

Please source the Watch Hang Over part 3 online Full movie online . Also follow. Please watch online the Watch fast and Furious 6 online Full movie online . Also Click here to watch online....
WHAT IS DIRECTORY