I am having trouble accessing and returning a variable that has been modified inside a function for use outside of the function. I understand that variables are scoped within functions, so I declared them outside of the function first and then reassigned them inside. However, I am unable to successfully return these variables for use in the main block of code.
let computerChoice = ""
let playerChoice = ""
gameChoices = ["rock", "paper", "scissors"]
/* Get the computers choice for the play*/
function getComputerChoice() {
let randomNumber = Math.floor(Math.random() * 3);
let computerChoice = gameChoices[randomNumber];
console.log(computerChoice);
return (computerChoice);
}
/* Get the players choice for the play*/
function getPlayerChoice() {
let playerChoice = prompt("Do you choose Rock, Paper or Scissors?").toLowerCase();
return (playerChoice);
}
getComputerChoice()
console.log(computerChoice)
getPlayerChoice()