find the power
of a number
[ exponentiation operator ]

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 exponentiation operator


Exponentiation operator **

The exponentiation operator ** is used to calculate the power of a number.

3 ** 4 34 3 × 3 × 3 × 381

3 ** 3 33 3 × 3 × 327

3 ** 2 32 3 × 39

3 ** 1 31 3

3 ** 0 301

3 ** -1 3-11/3


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

Using the exponent operator ** return the result of the base raised to the power of exponent.

return base ** exponent


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 base ** exp;

}

call function

findPower(num1, num2); returns ↴

81

Find the power of a number

Base
Exponent