js猜数字小游戏

//1.弹出框
//2.已经存在介于0 100 的任意数字
//3.比较数字大小
//4.可使用次数

//prompt 具有确定和取消按钮的弹出框
// var num = prompt("请输入0到100的数字");
// Math.random() 取随机数
// Math.floor()  向下取整
var num1 = Math.floor(Math.random() * 101 );
var count = 7;
console.log(num1);


while (count >= 0) {
    count--;
    var inpNum = prompt("请输入0到100的数字");
    if (inpNum < 0 || inpNum > 100) {
        alert("不符合 您还有" + count + "次输入机会");
    } else {
        if (count == 0) {
            alert("您的次数已经使用完了");
            break;
        } else if (inpNum > num1) {
            alert("输入大了,请重新输入 您还有" + count + "次输入机会");
        } else if (inpNum < num1) {
            alert("输入小了,请重新输入 您还有" + count + "次输入机会");
        }else if(inpNum = num1){
            alert("恭喜小主,输入正确,小主真厉害!")
            break;
        }
        }


    }

猜你喜欢

转载自blog.csdn.net/qq_38741169/article/details/88390847