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:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: JavaScript method cos()
Post your Comment