随机生成数字判断是否中奖

html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Documenttitle>
head>
<body>
<script>
    var num=parseInt(37*Math.random()) ;
    var time=1;
    var arr=[];
    for (j=0;j<3;j++) {
        for (i = 1; i <= 4; i++) {
            arr[i - 1] = prompt("请输入第" + i + "个四个数 ");
        if (arr[i - 1] <=   9 && arr[i - 1] >= 0&&arr[i-1]!="") {
        }      else {
        alert("请输入正确的数字");
        arr[i - 1] = prompt("请输入第" + i + "个四个数 ");
            i--;
            }
        }
        x = parseInt(arr[0]) + parseInt(arr[1]) + parseInt(arr[2]) + parseInt(arr[3]);
        alert(x);
        if (x!== num) {
        if (time == 3) {
        alert("很遗憾 你失败了")
        } else {
        alert("请再来一次");
            }
        time++;
        } else {
        alert("恭喜你 成功了");
        break
        }
    }
    document.write(num)
script>
body>
html>

你可能感兴趣的:(随机生成数字判断是否中奖)