I'm trying to figure out how to play out a single round of the game but when I run this function it does yield the correct results;
//AI Random Pick function
var AIpick = ['Rock', 'Paper', 'Scissors'];
function getComputerChoice() {
return AIpick[Math.floor((Math.random()*AIpick.length))];
}
console.log(getComputerChoice(AIpick));
Random pick function above works as intended.
//Single Round Of the Game
function round(playerSelection, computerSelection) {
if (playerSelection == "Rock" && computerSelection == "Paper") {
return "You lose! Paper beats Rock!";
} else if (playerSelection == "Paper" && computerSelection == "Rock") {
return "You won! Paper beats Rock!";
} else if (playerSelection == "Rock" && computerSelection == "Rock") {
return "Tie! Unga Bunga! Makes a nice sound tho!";
}
}
const playerSelection = "Rock";
const computerSelection = getComputerChoice();
console.log(round(playerSelection, computerSelection))
Something is problematic with the function above. It gives me the tie
option when the computerSelection = Paper
and 'you lose' option when the 'computerSelection = Rock'