Number :
<input type="text" id="txtnumber" /><br />
<br />
Root :
<input type="text" id="txtroot" /><br />
<br />
<button onclick="getrootval()">
Find Root</button>
<script>
function getrootval() {
var num = document.getElementById("txtnumber").value;
var root = document.getElementById("txtroot").value;
var str = root + "th root of " + num + " is ";
if (parseFloat(root) == 1.0) {
str = "First Root of " + num + " is ";
}
else if (parseFloat(root) == 2.0) {
str = "Square Root of " + num + " is ";
}
else if (parseFloat(root) == 3.0) {
str = "Cube Root of " + num + " is ";
}
num = Math.pow(num, (1 / parseFloat(root)));
alert(str + num);
}
</script>.This code is for finding nth root of a number using JavaScript.
With below code, we can find the nth root of a number by making use of Math.pow() function in javascript,
