I'm making a simple rock, paper, scissors game. And sometimes when I refresh the page nothing happens. When that happens, no errors are shown. I tried running this code on an online editor like w3schools, but the result is the same. What could be causing this problem?
Here's my code:
<body onload="game()">
<script>
function game(playerItem, computerSelection) {
function computerSelection() {
var arr = ["rock", "paper", "scissors"];
var computerSelection = arr[Math.floor(Math.random() * 3)];
return computerSelection;
}
var playerItem = "rock";
if (playerItem == "rock" & computerSelection() == "paper") {
document.write(rockVSpaper);
return;
};
if (playerItem == "rock" & computerSelection() == "scissors") {
document.write(rockVSscissors);
return;
};
if (playerItem == "rock" & computerSelection() == "rock") {
document.write(rockVSrock);
return;
};
}
var rockVSpaper = "You lose! The computer's paper wraps your rock.";
var rockVSscissors = "You won! Your rock make the computer's scissors blunt.";
var rockVSrock = "Tie! A Rock doesn't do anything with another rock.";
</script>
</body>