JavaScript Tutorial/Math/cos

Материал из Web эксперт
Перейти к: навигация, поиск

Math.cos()

The cos() method calculates the cosine of a number.

It returns a numeric value between -1 and 1, representing the cosine of an angle.



<html>
    <body>
    <script language="JavaScript">
    <!--
    function doMath(){
        var inputNum=document.form1.input.value;
        var result = Math.cos(inputNum);
        document.form1.answer.value = result;
    }
    -->
    </script>
    <form name=form1>
    This exanple calculates the cosine of the entered number.
    <br><br>
    Enter First Number:
    <input type="text" name="input" size=10>
    <input type="button" value="Calculate" onClick="doMath()">
    <br>
    The cosine is:
    <input type="text" name="answer" size=10>
    </form>
    </body>
    </html>