<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Match的对象实例</title>
    <link rel="stylesheet" href="">
    <script>
    var m=parseInt(prompt("请输入随机数的下限","0"));
    var n=parseInt(prompt("请输入随机数的上限","0"));
    with(document){
        //Math的属性和方法
        write("Math.E="+Math.E+"<br>");
        write("Math.LN2="+Math.LN2+"<br>");
        write("Math.LN10="+Math.LN10+"<br>");
        write("Math.LOG2E="+Math.LOG2E+"<br>");
        write("Math.LOG10E="+Math.LOG10E+"<br>");
        write("Math.PI="+Math.PI+"<br>");
        write("Math.SQRT1_2="+Math.SQRT1_2+"<br>");
        write("Math.SQRT2="+Math.SQRT2+"<hr>");
        //使用log方法计算自然数
        write("Math.log("+n+"):"+Math.log(n)+"<br>");
        write("Math.log("+m+"):"+Math.log(m)+"<br>");
        write("Math.log(Math.exp("+m+")):"+Math.log(Math.exp(m))+"<hr>");
        //使用sqrt方法计算平方根
        write("Math.sqrt("+m+"):"+Math.sqrt(m)+"<br>");
        write("Math.sqrt("+n+"):"+Math.sqrt(n)+"<hr>");
        //在for循环中使用random方法产生10个随机数
        document.write(m+"到"+n+"之间的随机数为:<br>");
        for(var i=0;i<10;i++){
            var reasult=Math.round(Math.random()*(n-m)+m);
            document.write(reasult+",");
        }
    }
    </script>
</head>
<body>
    
</body>
</html>

标签:JavaScript

你的评论