Home > Web Front-end > Front-end Q&A > How to implement n raised to the kth power in javascript

How to implement n raised to the kth power in javascript

WBOY
Release: 2022-01-28 11:33:21
Original
2047 people have browsed it

In JavaScript, you can use the pow() function of the Math object to realize n raised to the kth power. The syntax is "Math.pow(n,k)"; the return result of this function is n raised to the kth power. .

How to implement n raised to the kth power in javascript

The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.

How to implement n raised to the kth power in javascript

The pow() method returns x raised to the y power.

The syntax is:

Math.pow(x,y)
Copy after login

The example is as follows:

<html>
<head>
<meta charset="utf-8">
<title>123</title>
</head>
<body>
<p id="demo">单击按钮显示4*4*4的结果。</p>
<button onclick="myFunction()">点我</button>
<script>
function myFunction(){
document.getElementById("demo").innerHTML=Math.pow(4,3);
}
</script>
</body>
</html>
Copy after login

Output result:

How to implement n raised to the kth power in javascript

After clicking the button , Output result:

How to implement n raised to the kth power in javascript

Related recommendations: javascript learning tutorial

The above is the detailed content of How to implement n raised to the kth power in javascript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template