...

View Full Version : Resolved javascript to the power of



rhyz
06-20-2009, 10:42 AM
hello

quick question how do i do to the power of in javascript

eg

2 to the power of 2 = 4

thanks :)

Philip M
06-20-2009, 11:39 AM
var num = 2;
var exponent = 3;
var result = Math.pow(num,exponent); // 8



It is your responsibility to die() if necessary….. - PHP Manual

KevinJohnson
06-20-2009, 01:10 PM
hello

quick question how do i do to the power of in javascript

eg

2 to the power of 2 = 4

thanks :)

The answer should be in any very basic javascript book under "math functions" or "math operators".

...but since you asked:cool:




var Base = 2;
var Power = 2;
var Answer = Base ^ Power;



there ya go :D

Philip M
06-20-2009, 01:22 PM
var Base = 2;
var Power = 2;
var Answer = Base ^ Power;




Wrong!

In Javascript ^ means bitwise exclusive OR, e.g. 10^3=9

rhyz
06-20-2009, 03:21 PM
Thanks !!!

i thought ^ to start but when i tried i get 0 :)

silly me :)


Thanks !!!:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum