js的知识点15

  • Math.pow(n,m)    求n的m次方
  • Math.abs(n)          求n绝对值
  • Math.round(n)       求n的四舍五入的值
  • Math.floor(n)         求n的向下取整的值
  • Math.ceil(n)         求n的向上取整的值
  • Math.random()     获得一个0到1之间的随机数    注:能取到0但是不能取到1

                                    1.  求0到n之间的随机数:  Math.random()*n

                                    2.  求n到m之间的随机数(n<m)  Math.random()*(m-n)+n

案例:在页面输出6个10到30之间的两位数,且1输出的0~30的两位数中包括10和30,在此区间每个数出现的可能性相等。

      注:求任意两个数之间的随机数公式:  Math.floor(Math.random()*(大数-小数+1)+小数)

  • js的特殊字符

       ‘ :单引号

       “:双引号

      \:转义字符

     \r:回车

     \n:换行

   

猜你喜欢

转载自blog.csdn.net/qq_39368007/article/details/81914742