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)
}

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)
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.