TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Finding Nth Root Of A Number Using JavaScript
Midhun Tp
Aug 27
2016
Code
1.4
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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>
.
Root
Power
Math.pow
JavaScript