Takes x to the power of y.
There are some math calculations that require you to use exponents. Math.power(x, y) does not change the value of x or y, rather it returns the result of x to the power of y.
var z = Math.pow(4, 2); console.log(z);
Input the radius of a circle and hit "Calculate" to find the area of that circle. This example also uses Math.round to display results.
textLabel("title", "Area of a Circle"); textLabel("question", "What's the radius of your circle?"); textInput("radiusInput", ""); button("calculate", "Calculate"); textLabel("answer", ""); onEvent("calculate", "click", function( ) { var radius = getNumber("radiusInput"); var area = 3.14 * Math.pow(radius, 2); setText("answer", "Circle Area = " +Math.round(area)); });
Math.pow(x,y);
Name | Type | Required? | Description |
---|---|---|---|
x | Number | The base, or number which will be taken to the power of y | |
y | Number | The exponent or power |
A number representing x to the power of y.
Found a bug in the documentation? Let us know at documentation@code.org