I am working through TheOdinProject's rock paper scissors game. My playRound function is not yet completed and I am planning on expanding the "not a tie" message with winning and losing messages after I resolve my current issue. Currently, the console logs "not a tie" for every outcome regardless of whether the user and the computer chose the same selection.
Additionally, I am wondering if I am doing the right thing by calling getUserChoice and getComputerChoice in the playRound function; if I make variables for userChoice and computerChoice outside the playRound function (ex. let userChoice = getUserChoice) it prompts the user for a selection twice which I do not want.
Initially I was missing a 'return' in my getUserChoice function and I thought adding it would fix my issue however the same issue still remains.
Any help is greatly appreciated!
function getComputerChoice () {
let randomNumber = Math.floor(Math.random()*3);
switch (randomNumber) {
case 0:
console.log("rock");
return;
case 1:
console.log("paper");
return;
case 2:
console.log ("scissors");
return;
}
}
function getUserChoice () {
let caseInsensitiveUserSelection = prompt("Rock, paper or scissors?");
let userChoice = caseInsensitiveUserSelection.toLowerCase();
return userChoice;
}
function playRound() {
let userChoice = getUserChoice()
let computerChoice = getComputerChoice()
if (userChoice === computerChoice) {
console.log("Tie game!") }
else { console.log("not a tie") }
}
playRound()