lundi 24 février 2020

How to get javascript to prompt a question a set number times

Im trying to write a simple program that asks the user to guess a random number a set number of times. So far I have the following:

<!DOCTYPE html>
<html>
<head>
    <title>Decisions and Loops</title>
</head>
<body>

</body>
<script>

var rNum = Math.ceil(Math.random() * 30);

var myInput = Number (prompt ("Please enter your Guess: "));


if (myInput == rNum) {
    alert("Good guess");
    } 
    else if (myInput >= rNum){
        alert((prompt ("Sorry, guess if too low, try again"));
    } 
    else {
    alert((prompt ("Sorry, guess if too high, try again"));
    }

</script>
</html>

Two issues 1. For some reason this is not working. 2. How do I get the program to iterate through the loops a number of times? Any assistance would be appreciated.




Aucun commentaire:

Enregistrer un commentaire