Javascript examples for Math:cos
The cos() method returns the cosine of a number.
Parameter | Description |
---|---|
x | Required. A number |
A Number, from -1 to 1, representing the cosine of an angle, or NaN if the value is empty
The following code shows how to return the cosine of a number:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*from w w w. j a va 2 s . c o m*/ var a = Math.cos(Math.PI); var b = Math.cos(2 * Math.PI); document.getElementById("demo").innerHTML = a + "<br>" + b; } </script> </body> </html>