jeudi 9 juillet 2015

Trying to make a randomly generated number guessing game

I'm supposed to make a random number guessing game.

So I know I need to randomly generate a number between 0 - 50, and the user needs to guess. Based on their guess I have to tell them if they're too low or too high.

This is what I have so far, but I don't know what I'm supposed to do next. (Or if it's right.)

<!DOCTYPE html>
<html>
<head>
    <title>Number Game</title>
</head>
<body>
    <h2>I'm thinking of a number between 0 and 50...</h2>
    <div id="output"></div>
    <input id="txtInput" /><br>
    <button onClick="checkInput();genNum();">Is this your number?</button>
    <script src="js/main.js">
        var outputDiv = document.querySelector("#output");

        function checkInput() {
            var guess = parseInt(txtInput.value);
        }

        function genNum() {
            txtInput.value = Math.round(Math.random() * 50);
        }
    </script>
</body>
</html>




Aucun commentaire:

Enregistrer un commentaire