find the Nth root
of a number
[ exponentiation operator ]

Find the Nth root of a number

Write a function that takes two numbers, the first number representing the root and the second representing the number that we want to find the root of.

root → number to calculate

number → number whose root is to be found


In mathematics, the general root, or the nth root of a number a is another number b that

when multiplied by itself n times, equals a

In equation format ...

na = b

bn = a


Root of a number

The root of a number n is another number, which when multiplied by itself a given number of times, equals n

For example, the third root of 64 is 4, because if you multiply three fours together you get 64 4 × 4 × 4 = 64

This would be written as 3√ 64 = 4

This would be spoken as "the third root of 64 is 4" or "the cube root of 64 is 4".

The second root is usually called the square root

The third root of a number is usually called the cube root

After that, they are called the nth root, for example the 4th root, 5th root, 6th root, etc.

If root is missing, it is assumed to be 2, the square root.


Example ...

Enter root to find and the number ...

281 returns → 9 9 × 9 = 81

327 returns → 3 3 × 3 × 3 = 27

416 returns → 2 2 × 2 × 2 × 2 = 16

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


Find the Nth root of a number using the exponentiation operator **


Exponentiation

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

number (1 / root)

root number to be multiplied by itself

number number whose root is to be found

To find the root of a number using exponential notation, rewrite the root as a fractional exponent and solve.

For the nth root of a number x write it as x1/n

For example, the square root of 25 is 251/2 = 5

and the cube root of 27 is 271/3 = 36


Exponentiation operator **

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

281 same as 811/2

327 same as 271/3

416 same as 161/4

Using the exponentiation operator.

811/2 81 ** (1/2) 9

271/2 27 ** (1/3) 3

161/2 16 ** (1/4) 2


Initialize a variable to hold the root value.

const num1 = 2; → user input

Initialize a variable to hold the number whose root is to be found.

const num2 = 81; → user input


Define a function findRoot to find the root of a number.

function findRoot(str) {}

The function takes two numbers as input num1, num2 representing the root and the number whose root is to be found.

num1 number

num2 root

Using the exponent operator ** return the result of num raised to the power of (1/root)

return num ** (1 / root)


Call the function with ↴

findRoot(num1, num2);


Find the Nth root of a number.

281 → find square root of 81

const num1 = 2;

const num2 = 81;

function findRoot(root, num) {

return num ** (1 / root);

}

call function

findRoot(num1, num2); returns ↴

9


Alternative to find the square root of a number using built-in Math.sqrt() method ↴

Math.sqrt(81); returns ↴

9

Find the Nth root of a number

root √
number
to decimal places