运行 ❯
获取您的
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>JavaScript Math</h1> <h2>The Math.cos() Method</h2> <p>Math.cos() returns the cosine of an angel given in radians.</p> <p>To use degrees, convert the degrees to radians first:</p> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = "Cosine of 0 degrees is: " + cosine(0) + "<br>" + "Cosine of 60 degrees is: " + cosine(60) + "<br>" + "Cosine of 90 degrees is: " + cosine(90) + "<br>" + "Cosine of 180 degrees is: " + cosine(180) + "<br>" + "Cosine of 240 degrees is: " + cosine(240) + "<br>" + "Cosine of 360 degrees is: " + cosine(360); function cosine(degree) { // radians = degrees * PI / 180 let x = Math.cos(degree * Math.PI / 180); return x.toFixed(2); } </script> </body> </html>