[Solved] Why the program not run correctly?


Like AnthonyLeGovic said:

you need to be rigorous when programming

here is what you are looking for:

<html>
<head>
    <title>test</title>
    <script language="javascript">
        var numRand = 0;
        var numGuess = 0;
        var numTry = 1;

        function setRand(){
            numRand = Math.floor((Math.random()*100)+1);
            numTry = 0;
            alert("done");
        }

        function guess(){
            var msg = document.getElementById("message");
            numGuess=Number(document.getElementById("guess").value);
            if(numGuess>numRand){
                msg.innerHTML = "lower than!";
            }
            else if(numGuess<numRand){
                msg.innerHTML = "grater than!";
            }
            else {
                msg.innerHTML = "equal! tried " + numTry +"times";
            }
            numTry++;
        }
    </script>
</head>
<body>
    <input type="text" id="guess" />
    <input type="button" onclick="setRand()" value="Random" />
    <p id="message"></p>
    <input type="button" onclick="guess()" value="Check" />
</body>

do not forget language="javascript" in your script tag else your script will not work!

0

solved Why the program not run correctly?