I'm coding a basic rock paper scissors game.
the 2 functions are working fine. the issue is the winner variable is always undefined..
I don't know what to do to correct this. I want it to say who won, computer or the human(user).
function game(x, y) {
var inputC = computerPlay();
var inputH = humanPlay();
var winner;
if (inputH == 'paper' && inputC == 'scissors') {
console.log('Computer wins with Scissors ');
if (inputH == 'scissors' && inputC == 'rock') {
console.log('Computer wins with rock');
if (inputC == 'paper' && inputH == 'rock') {
console.log('Computer wins with paper');
}
}
winner = "computer";
} else if (inputC == 'paper' && inputH == 'scissors') {
console.log('Human wins with Scissors ');
if (inputC == 'scissors' && inputH == 'rock') {
console.log('Human wins with rock');
if (inputH == 'paper' && inputC == 'rock') {
console.log('Human wins with paper');
}
}
winner = "human";
}
document.getElementById("text1").innerHTML = winner;
console.log("result is: " + winner + " wins");
}
I'm sure its something minor but my god I'm all out of ideas.
inputH == 'paper' && inputC == 'scissors'orinputC == 'paper' && inputH == 'scissors'all other combinations will result in winner being undefined ... don't nest if's like that without understanding