View Full Version : Javascript square root

1337coder

12-12-2006, 09:41 PM

Sorry, I'm still a novice at Javascript. I cannot manage to do a square root operation. I am using the coding:

var a = Math.sqrt(b);

Anyhelp would be appreciated. Thanks.

david_kw

12-12-2006, 11:35 PM

Looks fine to me as long as b is an integer. Try just typing

alert(Math.sqrt(9));

and see if it returns 3 to cut out the guesswork

david_kw

1337coder

12-13-2006, 02:58 AM

For some reason, putting it into an alert worked, and it also worked with a variable. Thanks a lot, David

dwees

12-13-2006, 07:43 AM

b definitely does not have to be an integer, it can be any real number (ie loads of decimal places will work).

Dave

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.