find the power
of a number
[ Math.pow ]

Find the power of a number

Write a function that takes two numbers, the first number representing the base number and the second representing the exponent.

The power of a number is the result of raising the base to the power of the exponent.

base → number that is being multiplied.

exponent → number that indicates how many times the base is multiplied by itself.


Example ...

Find 2 to the power of 3

23 → 2 × 2 × 2 → 8

Find 3 to the power of 4

34 → 3 × 3 × 3 × 3 → 81

Numbers are used to represent both integer and floating-point values.

Numbers are most commonly expressed in literal forms like 255 or 3.14159 ↴

let num1 = 5; → number

let num2 = 2.5; → number

let num3 = num1 + num2;

console.log(num3); returns ↴

7.5 → number


Exponentiation

Exponentiation is the mathematical process of multiplying a number by itself, raised to the power of another number.

base exponent

base number to multiply.

exponent number of times to multiply the base by itself.


Find the power of a number using the Math.pow() method.


Math.pow() static method returns the value of a base raised to a power.

Math.pow(x, y) = xy

Math.pow(2, 2) 22 2 × 2 → 4

Math.pow(2, 3) 23 2 × 2 × 2 → 8

Math.pow(3, 3) 33 3 × 3 × 3 → 27

Math.pow(3, 4) 34 3 × 3 × 3 × 3 → 81

Math.pow() is equivalent to the exponent operator ** except Math.pow() only accepts numbers.


Initialize a variable to hold the base value.

const num1 = 3; → user input

Initialize a variable to hold the exponent value.

const num2 = 4; → user input


Define a function findPower to find the power of a number.

function findPower(str) {}

The function takes two numbers as input num1, num2 representing the base and exponent and returns the result of raising the base to the power of the exponent.

num1 → base

num2 → exponent

return Math.pow(base, exp)


Call the function with ↴

findPower(num1, num2);


Find 3 to the power of 4 → 34

const num1 = 3;

const num2 = 4;

function findPower(base, exp) {

return Math.pow(base, exp);

}

call function

findPower(num1, num2); returns ↴

81

Find the power of a number

Base
Exponent
⇑