2.Math对象.html 860 B

123456789101112131415161718192021222324
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. document.write(Math.E + '<br>'); // Math.PI 常量
  11. console.log(Math.abs(-10)); // Math.abs 绝对值
  12. console.log(Math.ceil(10.5)); // Math.ceil 向上取整
  13. console.log(Math.floor(10.5)); // Math.floor 向下取整
  14. console.log(Math.round(10.2)); // Math.round 四舍五入
  15. console.log(Math.random()*10); // Math.random 随机数
  16. // 随机取整x-y Math.round(Math.random() * (y-x) + x)
  17. console.log(Math.round(Math.random()*5+5));
  18. console.log(Math.pow(2,3)); //Math.pow(x,y) x的y次幂
  19. console.log(Math.sqrt(81)); // Math.sqrt 算术平方根
  20. </script>
  21. </body>
  22. </html>