The acos() method returns the arccosine of a number.
acos() |
Yes | Yes | Yes | Yes | Yes |
Math.acos(x);
Parameter | Description |
---|---|
x | Required. A number |
The returned value is between 0 and PI radians.
If the parameter is outside the range -1 to 1, the method will return NaN.
acos(-1) returns PI.
The following code shows how to calculate the arccosine of a number.
<html>
<body>
<script language="JavaScript">
function doMath() {<!--from www .ja v a2 s.c o m-->
var inputNum = document.form1.input.value;
var result = Math.acos(inputNum);
document.form1.answer.value = result;
}
</script>
<form name=form1>
<br> Enter Number: <input type="text" name="input" size=10>
<input type="button" value="Calculate" onClick='doMath()'> <br>
The arccosine is: <input type="text" name="answer" size=10>
</form>
</body>
</html>