Rock Paper Scissors


#1

Hello. While the console doesn’t show me any error alerts, changing from return to console.log so I could check out how things were working also displays none of the strings. Where did I go wrong?

This is what the code looks like now.

let gameChoices = [‘rock’, ‘paper’, ‘scissors’];

let playerScore;
let computerScore;

const computerSelection = gameChoices[Math.floor(Math.random() * 3)];
let playerSelection = prompt(“Pick One:”).toLowerCase();

function playRound(playerSelection, computerSelection) {

if (playerSelection == “rock” && computerSelection == “rock”) {
console.log(“This is a Tie.”)
} else if (playerSelection == “rock” && computerSelection == “paper”) {
console.log(“You Lose! Paper Beats Rock.”)
} else if (playerSelection == “rock” && computerSelection == “scissors”) {
console.log(“You Win! Rock Beats Scissors.”)
} else if (playerSelection == “scissors” && computerSelection == “scissors”) {
console.log(“This is a Tie.”)
} else if (playerSelection == “scissors” && computerSelection == “rock”) {
console.log(“You Lose! Rock Beats Scissors.”)
} else if (playerSelection == “scissors” && computerSelection == “paper”) {
console.log(“You Win! Scissors Beat Paper.”)
} else if (playerSelection == “paper” && computerSelection == “paper”) {
console.log(“This is a Tie.”)
} else if (playerSelection == “paper” && computerSelection == “rock”) {
console.log(“You Win! Paper Beats Rock.”)
} else if (playerSelection == “paper” && computerSelection == “scissors”) {
console.log(“You Lose! Scissors Beat Paper.”)
} else (playerSelection != gameChoices) {
console.log(“Hey!!”);
}
}


#2

Assuming you haven’t left out any code, it looks like you’re defining the function playRound, but never calling it! To do that, add the following line of code to the bottom of your file:

playRound(playerSelection, computerSelection);

This should cause at least something to be logged to the console.


Additionally, I think it may be a good idea to turn the following line into a function as well.

const computerSelection = gameChoices[Math.floor(Math.random() * 3)];

Hope this helps!


#3

Oh man, I cannot believe I missed that, out of any mistake possible. Thanks for checking it out! Thank you for the other suggestion as well, I’ll be sure to change it before implementing the loop.