How to use the Math.cos() function to get the cosine of a number in JavaScript

1 Answer

0 votes
document.write("Math.cos(-1) = " + Math.cos(-1) + "<br />");
document.write("Math.cos(1) = " + Math.cos(1) + "<br />");
document.write("Math.cos(0) = " + Math.cos(0) + "<br />");
document.write("Math.cos(-0) = " + Math.cos(-0) + "<br />");
document.write("Math.cos(0.9) = " + Math.cos(0.9) + "<br />");
document.write("Math.cos(Math.PI) = " + Math.cos(Math.PI) + "<br />");
document.write("Math.cos(Math.PI * 2) = " + Math.cos(Math.PI * 2) + "<br />");
document.write("Math.cos(Math.PI / 2) = " + Math.cos(Math.PI / 2) + "<br />");
document.write("Math.cos(Math.PI / 3) = " + Math.cos(Math.PI / 3) + "<br />");

 
/*
run

Math.cos(-1) = 0.5403023058681398
Math.cos(1) = 0.5403023058681398
Math.cos(0) = 1
Math.cos(-0) = 1
Math.cos(0.9) = 0.6216099682706644
Math.cos(Math.PI) = -1
Math.cos(Math.PI * 2) = 1
Math.cos(Math.PI / 2) = 6.123233995736766e-17
Math.cos(Math.PI / 3) = 0.5000000000000001
 
*/

 



answered Aug 2, 2016 by avibootz
...