20.Math对象.html 875 B

123456789101112131415161718192021222324252627
  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. // 变量
  11. var a = '1';
  12. // 字面量 1 2 3 4 true '哈哈'
  13. console.log(Math.PI);//π
  14. console.log(Math.E);//常量
  15. console.log(Math.pow(2,6));//x的y次幂
  16. console.log(Math.ceil(12.3));//向上取整
  17. console.log(Math.floor(12.4));//向下取整
  18. console.log(Math.abs(-2));//绝对值
  19. console.log(Math.sqrt(81));//算术平方根
  20. console.log(Math.round(2.7));//四舍五入
  21. console.log(Math.random()*10);//随机数
  22. // 随机数x-y取整
  23. // Math.round(Math.random() * (y-x) + x)
  24. console.log(Math.round(Math.random() * (10-1) + 1));
  25. </script>
  26. </body>
  27. </html>