I have been beating my brains out for the past few days trying to figure out why the functions being called are undefined.
Here is how the console.log looks at the start of the game:
Expected Outcome:
When the playRound() is called, the if/else statements should be console.logging the correct statements. Like so:
const playRound = (playerSelection, computerSelection) => {
playerSelection = playerWeapon();
computerSelection = selectedWeapons();
console.log("playerWeapon: ", playerSelection);
console.log("computerWeapon: ", computerSelection);
if (computerSelection === "📜" && playerSelection === "🪨") {
console.log("Computer Wins!");
} else if (playerSelection === "📜" && computerSelection === "🪨") {
console.log("You Win!");
}
if (computerSelection === "✂" && playerSelection === "📜") {
console.log("Computer Wins!");
} else if (playerSelection === "✂" && computerSelection === "📜") {
console.log("You Win!");
}
if (computerSelection === "🪨" && playerSelection === "✂") {
console.log("Computer Wins!");
} else if (playerSelection === "🪨" && computerSelection === "✂") {
console.log("You Win!");
}
if (computerSelection === playerSelection) {
console.log("Tie!");
}
}
Once I am able to get the code working properly, I will then use DOM manipulation, to have the game results displayed on the webpage instead of the console.
Current Outcome:
In the playRound(), I am calling both the selectedWeapons() and playerWeapon(). But both of the functions, are undefined and I am unable to get the values in the playRound() to use for the if/else statements. BUT, the only console.log message that's given is "Tie".Why is that? 🤔
I tried creating other functions, calling functions in other functions.I've also been playing around with the for..loops and event listeners.
Here is the console.log after playing a few rounds:
Any help is greatly appreciated.


Discussion (0)