JavaScript guess number game

Time:2020-11-7

Code implementation:

Document
    
        //Functions that generate random integers
        function getRandom(min, max) {
            return Math.floor(Math.random() * (max - min + 1)) + min;
        }
        //Get random integers from 1 to 50
        var random = getRandom(1, 50);
        var flag = 0;
        //Dead loop. If you run out of 5 chances or guess right, you will exit the loop
        while (true) {
            Var num = prompt ('Please guess a number from 1 to 50: ');
            if (num > random) {
                flag++;
                It's too big! You still have '+ (5 - flag) +'opportunity');
            } else if (num < random) {
                flag++;
                It's too small! You still have '+ (5 - flag) +'opportunity');
            } else {
                Congratulations, you're right! The number is' + random);
                break;
            }
            if (flag == 5) {
                It's so delicious! The opportunity is exhausted! The correct number is' + random);
                break;
            }
        }