JavaScript: Calculate the nth root of a number
JavaScript Math: Exercise-26 with Solution
Calculate nth Root of a Number
Write a JavaScript function to calculate the nth root of a number.
Test Data :
console.log(nthroot(64, 2));
8
console.log(nthroot(64, -2));
0.125
Sample Solution:
JavaScript Code:
Output:
8 0.125
Visual Presentation:
Flowchart:

Live Demo:
For more Practice: Solve these Related Problems:
- Write a JavaScript function that calculates the nth root of a number using exponentiation and handles fractional exponents.
- Write a JavaScript function that implements the nth root calculation iteratively using the Newton-Raphson method.
- Write a JavaScript function that validates inputs for nth root calculation and returns an error for invalid parameters.
- Write a JavaScript function that calculates the nth root and returns the result rounded to a specified precision.
Improve this sample solution and post your code through Disqus.
Previous: Write a JavaScript function to make currency math (add, subtract, multiply, division etc.).
Next: Write a JavaScript function to calculate degrees between 2 points with inverse Y axis.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics