JavaScript method cos()

This section illustrates you the use of JavaScript method cos(). The method cos() returns the cosine of the specified number. It returns the numeric value between -1 and 1.

JavaScript method cos()

JavaScript method cos()

     

This section illustrates you the use of JavaScript method cos(). The method cos() returns the cosine of the specified number. It returns the numeric value between -1 and 1.

Its syntax is:

Math.cos( x )

where x is any number.

 

Here is the code:

<html>
<script>
function calculate(){
var i = Math.cos(30);
document.write("The cos value of 30: " + i); 
document.write("<br>");
var j= Math.cos(90);
document.write("The cos value of 90: " + j); 
}
</script>
<body>
<h2>Use of method cos()</h2>
<button onclick="calculate()">Show Cos value</button>
</body>
</html>

Output will be displayed as:

On clicking the button, the cosine values of the specified numbers will be displayed:

Download Source Code: