Documentation.
Anything placed in the left box above is evaluated as JavaScript, and the result is displayed at the right. All script is legal, but methods like "document.write" and "return" aren't necessary. The following tutorial assumes no previous experience with JavaScript.
Obviously the four main arithmetic functions apply ( + , , * , / ). Additionally there is a modular arithmetic function, %. These five functions are binary functions, meaning they operate on two values. Their syntax is as follows:
4+2 42 4*2 4/2 4%2
These five inputs would respectively result in the following five outputs:
6 2 8 2 0
More complex calculations can be done using parentheses. For example, (10%3+2*(65.5))/21 evaluates to 0.
Transcendental and other functions are supported too, using the JavaScript Math object. In PlayGround these functions can also be called without the "Math.", as shown in the last column:
Notation | JavaScript Syntax | PlayGround Syntax
|x| | Math.abs(x) | abs(x)
| xy | ex √x x2 Math.pow(x,y) | Math.exp(x) Math.sqrt(x) pow(x,y) | exp(x) sqrt(x) sq(x) ln x | Math.log(x) | ln(x) or log(x,b)
| sin x | cos x tan x Math.sin(x) | Math.cos(x) Math.tan(x) sin(x) | cos(x) tan(x) arcsin x | arccos x arctan x Math.asin(x) | Math.acos(x) Math.atan(x) arcsin(x) | arccos(x) arctan(x) x | x Math.floor(x) | Math.ceil(x) Math.round(x) floor(x) | ceil(x) round(x,n) Math.min(a,b) | Math.max(a,b) min([a,b,c,...]) | max([a,b,c,...]) Math.random() | random(b1,b2,n)
| |
Notation | JavaScript Syntax | PlayGround Syntax
π | Math.PI | pi
| e | Math.E | e
| |
PlayGround Syntax | Input Type(s) | Description
base(x,b1,b2) | Base-10 Integers | converts x from base b1 to b2 (x can be an array)
| factor(x) | Integer >1 | returns an array of prime factors of x
| factorial(x,n) | pfactorial(x) Integer >0 | computes the n-factorial of x | multiplies all primes ≤ x isprime(x) | Integer >1 | tests whether an integer is prime
| fibonacci(x) | Integer >0 | computes the xth term of the Fibonacci sequence
| gcd([a,b,c,...]) | lcm([a,b,c,...]) Array of Numbers | Array of Numbers computes the greatest common factor of a,b,c,... | computes the least common multiple of a,b,c,... product([a,b,c,...]) | sum([a,b,c,...]) Array of Numbers | Array of Numbers computes a*b*c*... | sums a+b+c+... sign(x) | Number | returns the sign of x: either 1, 0, or 1
| csc(x) | sec(x) cot(x) Number | Number Number computes the cosecant of x | computes the secant of x computes the cotangent of x arccsc(x) | arcsec(x) arccot(x) Number | Number Number computes the inverse cosecant of x | computes the inverse secant of x computes the inverse cotangent of x sinh(x) | cosh(x) tanh(x) Number | Number Number computes the hyperbolic sine of x | computes the hyperbolic cosine of x computes the hyperbolic tangent of x csch(x) | sech(x) coth(x) Number | Number Number computes the hyperbolic cosecant of x | computes the hyperbolic secant of x computes the hyperbolic cotangent of x arcsinh(x) | arccosh(x) arctanh(x) Number | Number Number computes the inverse hyperbolic sine of x | computes the inverse hyperbolic cosine of x computes the inverse hyperbolic tangent of x arccsch(x) | arcsech(x) arccoth(x) Number | Number Number computes the inverse hyperbolic cosecant of x | computes the inverse hyperbolic secant of x computes the inverse hyperbolic cotangent of x |
Notes.
All PlayGround functions and constants can be overwritten, but other functions may be adversely affected.
Several functions use variables i, j, and k, so it is advised that these not be used.
The following list gives function values that are implied when absent:
base(x,b2)=base(x,10,b2)
factorial(x)=factorial(x,1)
log(x)=log(x,e)
random(b1,b2)=random(b1,b2,0)
round(x)=round(x,0)
Computation Examples
abs(17)=17
arccos(0)=1.5707963267948965
arccosh(1)=0
base(5,2)=101
ceil(pi/2)=2
exp(2)=7.38905609893065
factor(60)=[2,2,3,5]
factorial(5)=120
factorial(5,2)=15
fibonacci(17)=1597
floor(pi/2)=1
gcd(20,25)=5
lcm(20,25)=100
log(100,10)=2
ln(2)=0.6931471805599453
max([5,65,1105])=1105
min([5,65,1105])=5
pow(2,3)=8
product([1,3,5,7,9])=945
random(1,4,5) could equal 1.61803, 2.71828, 3.14159, and many other values
round(pi/2)=2
round(pi/2,2)=1.57
sign(3)=1
sign(3)=1
sin(pi/2)=1
sinh(ln(2))=.75
sqrt(289)=17
sum([1,2,3,4,5,6,7,8,9])=45