I am so lost! My console.log is printing everything in my function and I can’t figure out why. Please give me a clue to figure out my mistake.
I appreciate your help!
treedreamin
This is the code:
const getUserChoice = (userInput) => {
userInput = userInput.toLowerCase();
if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') {
return userInput;
} else {
console.log('Invalid input')
}
};
function getComputerChoice() {
let randomNumber = Math.floor(Math.random() * 3);
switch (randomNumber) {
case 0:
return 'Rock';
break;
case 1:
return 'Paper';
break;
case 2:
'Scissors';
break;
}
};
function determineWinner(getUserChoice, getComputerChoice) {
if (getUserChoice === getComputerChoice) {
return 'The game is a tie!' ;
}
if (getUserChoice === 'rock'){
if (getComputerChoice === 'paper')
return 'The computer won!';
} else {
return 'You won!' ;
}
if (getUserChoice === 'paper'){
if (getComputerChoice === 'scissors')
return 'The Computer won! ';
else {
return 'You won!';
}
}
};
if (getUserChoice === 'scissors') {
if (getComputerChoice === 'paper')
return 'You won!';
else {
return 'Computer won!';
}
}
if (getUserChoice === 'rock') {
if (getCmputerChoice === 'scissors')
return 'You won!';
else {
return 'Computer won!';
}
}
const playGame = () => {
const userChoice = getUserChoice('rock');
const computerChoice = getComputerChoice();
console.log('You threw: ' + getUserChoice);
console.log('The computer Threw: ' + getComputerChoice);
console.log(determineWinner(getUserChoice, getComputerChoice));
}
playGame()
And this is what is printing on the console:
You threw: (userInput) => {
userInput = userInput.toLowerCase();
if (userInput === ‘rock’ || userInput === ‘paper’ || userInput === ‘scissors’) {
return userInput;
} else {
console.log(‘Invalid input’)
}
}
The computer Threw: function getComputerChoice() {
let randomNumber = Math.floor(Math.random() * 3);
switch (randomNumber) {
case 0:
return ‘Rock’;
break;
case 1:
return ‘Paper’;
break;
case 2:
‘Scissors’;
break;
}
}
You won!