11_ for 练习 _ Math.sqrt

  • <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <title>Is Prime Number? Better way.</title>
    </head>
    <body>
    <script type="text/javascript">
    var xNumber = +prompt("请输入一个大于1的数字:");
    var isPrimeNumber = true; if(xNumber>1 && xNumber != NaN)
    {
    for(i=2; i<Math.sqrt(xNumber); i++)
    {
    if(xNumber%i==0)
    {
    isPrimeNumber = false;
    break;
    }
    }
    }
    if(isPrimeNumber)
    {
    document.write(xNumber+" is a Prime Number.");
    }
    else
    {
    document.write(xNumber+" is NOT a Prime Number.");
    }
    </script>
    </body>
    </html>
上一篇:在笛卡尔坐标系上描绘函数2*x+Math.sqrt(5-x*x)及其共轭函数2*x-Math.sqrt(5-x*x)曲线


下一篇:Math.cbrt() Math.sqrt() Math.pow()