An Interest In:
Web News this Week
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
- April 13, 2024
Need help with The Odin's Project, Rock Paper Scissors assignment
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.
Original Link: https://dev.to/taepal467/need-help-with-the-odins-project-rock-paper-scissors-assignment-19ie
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To