Rock paper scissors

hi everyone. who can put me to the bug in my code as i have checked severally but get an error code on if userchoice is ‘rock’. here is my code, thanks. I need help!

const getUserChoice = userInput => {

userInput = userInput.toLowerCase();

if (userInput === ‘rock’|| userInput ===‘paper’ ||userInput === ‘scissors’){

return userInput;

} else{

console.log(‘error, please check your spelling’);

}

};

const getComputerChoice = () => {

const randomNumber = Math.floor(Math.random() * 3);

switch(randomNumber){

case 0:

return 'rock';

case 1:

return 'paper';

case 2: 

return 'scissors';

}

};

const determineWinner = (userChoice, computerChoice) =>{

if (userChoice === computerChoice){

return ‘The game na tie’;

}

};

if (userChoice === ‘rock’) {

if (computerChoice ===‘paper’) {

return 'The computer won';

} else {

return 'congratulations, you won genius';

}

if (userChoice === ‘paper’) {

if (computerChoice === ‘scissors’) {

return 'The computer won!';

} else {

return 'You won!';

}

}

if (userChoice === ‘scissors’) {

if (computerChoice === ‘rock’) {

return 'The computer won!';

} else {

return 'You won!';

}

}

};

const playGame = () => {

const userChoice = getUserChoice(‘scissors’);

const computerChoice = getComputerChoice();

console.log('You threw: ’ + userChoice);

console.log(‘The computer threw:’ + computerChoice);

};

Hello @ilemonakennethakpa, welcome to the forums! Notice how you end your determineWinner function here:

if (userChoice === computerChoice){

return ‘The game na tie’;

}

};<--this ends the function

That means that code, such as the rest of the if blocks that determine the winner, aren’t in the function, and therefore can’t access function parameters, like userChoice.

oh, i will try this and see if it works. Thank you for your support.

1 Like