0

I am just toying around trying to learn javascript. I find it pretty neat. I am writing this code and I have been racking my brain for a while now. I know it's probably pretty obvious, but what am I doing wrong here?

Thanks in advance!

function chooseGame() {
    var choice = document.getElementById("gameChoice").value
    if (choice == 1) {
        guessGame()
    }
    else {
        battleBot()
    }
}

function guessGame() {
   var randomnumber = Math.floor(Math.random() * 51)
   var guess = prompt("Please enter a number between 1 and 50", "")
   do {
        if (guess > randomnumber) {
        alert("Guess lower!")
        }
        else (guess < randomnumber);
        alert("Guess higher!")
        }
   while (guess != randomnumber)
}
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by as.bhanuprakash
0

Below is the edited version of guessGame() function.
Hope it helps

function guessGame() {
   var randomnumber = Math.floor(Math.random() * 51);
   
   do {
        var guess = prompt("Please enter a number between 1 and 50", "")
        if (guess > randomnumber) {
            alert("Guess lower!");
        }
        else if (guess < randomnumber) {
            alert("Guess higher!");
        }
        
   }
   while (guess != randomnumber)
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.