Looking for assistance with a program I've been working on. In this program, there are three dice and three players. Player 1 rolls die 1, player 2 rolls die 2, and player 3 rolls die 3. The goal is to determine the winner based on who gets the highest number (between 1-6). However, I'm struggling to write an if-else statement that accurately displays the winner. Here's some code I've attempted:
if (randomNumber1 > randomNumber2 || randomNumber3) {
document.querySelector("h1").innerHTML = "Player 1 Wins! 🚩";
}
else if (randomNumber2 > randomNumber1 || randomNumber3) {
document.querySelector("h1").innerHTML = "Player 2 Wins! 🚩";
}
else if (randomNumber3 > randomNumber1 || randomNumber2) {
document.querySelector("h1").innerHTML = "Player 3 Wins! 🚩";
}
else {
document.querySelector("h1").innerHTML = "No Winner!";
}
I've encountered issues where the program incorrectly declares the winner. For instance, when player 1 has a 5 and player 3 has a 6, it still claims player 1 as the winner. It seems like my if-else logic is off. Can anyone provide guidance on how to correct this? I'm relatively new to coding and have been grappling with this problem all day. To assist me better, please show me the corrected code formatting. Feel free to modify the code I've already written.