Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Finding Nth Root Of A Number Using JavaScript
WhatsApp
Midhun Tp
Aug 27
2016
1.4
k
0
1
With below code, we can find the nth root of a number by making use of Math.pow() function in javascript,
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>
.
JavaScript
Math.pow
Power
Root
Up Next
Finding Nth Root Of A Number Using JavaScript