The cos() method returns the cosine of a number.
cos() |
Yes | Yes | Yes | Yes | Yes |
Math.cos(x);
Parameter | Description |
---|---|
x | Required. A number |
The cos() method returns a numeric value between -1 and 1, which represents the cosine of the angle.
The following code shows how to calculate the cosine of a number.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function doMath() {<!-- ww w. j av a2s. co m-->
var inputNum = document.form1.input.value;
var result = Math.cos(inputNum);
document.form1.answer.value = result;
}
</script>
</head>
<body>
<form name=form1>
<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>