Hello! I am a beginner in JavaScript and I am trying to create a simple rock, paper, scissors game. However, when I run the code, I receive two prompt messages and an error saying 'TypeError: playerOneChoice is not a function'. What mistake did I make? Thank you very much.
function getPlayerOneChoice(){
var playerOneInput = prompt('Hey there! What is your choice: rock, paper, or scissors?');
playerOneInput = playerOneInput.toLowerCase();
if(playerOneInput === 'rock' || playerOneInput === 'paper' || playerOneInput === 'scissors'){
return playerOneInput;
} else {
console.log('Invalid Choice!!!');
}
}
function getPlayerTwoChoice(){
var playerTwoInput = prompt('And what\'s your pick? Rock, paper, or scissors?');
playerTwoInput = playerTwoInput.toLowerCase();
if(playerTwoInput === 'rock' || playerTwoInput === 'paper' || playerTwoInput === 'scissors'){
return playerTwoInput;
} else {
console.log('Invalid selection!!');
}
}
function determineWinner(playerOneChoice, playerTwoChoice) {
if(playerOneChoice == playerTwoChoice) {
console.log('It\'s a Tie!');
}
if(playerOneChoice === 'rock'){
if(playerTwoChoice === 'scissors'){
return 'You win with rock!';
} else {
return 'You win with paper!';
}
}
if(playerOneChoice === 'scissors'){
if(playerTwoChoice === 'paper'){
return 'Congratulations, scissors won!';
} else{
return 'Scissors win this time!';
}
}
if(playerOneChoice === 'paper'){
if(playerTwoChoice === 'rock'){
return 'Paper wins!';
} else {
return 'Rock beats paper!';
}
}
}
function playGame() {
var playerOneChoice = getPlayerOneChoice();
var playerTwoChoice = getPlayerTwoChoice();
console.log('Player One picked: ' + playerOneChoice);
console.log('Player Two picked: ' + playerTwoChoice);
console.log(determineWinner());
}
playGame();