Rock Paper Scissors game failing

CODE

Hi!

I’ve spent days trying to figure out why this game is not functioning as expected but I guess I’m just too green to be able to figure it out!

*Not only is it returning “undefined” on screen for the userSelection, but the outcome (You win, You Lose, It’s a tie…) is almost never accurate based on the IF/ELSE function I added…

Thank you so much!!!

Hello @everythingisnot

you going great but there some note here

  1. you missing many semicolon
  2. no need to set the onclick attribute in the html tags
  3. you only need to set the addEventListener for the button do not but that on function and inside that EventListener you need to set the userSelection then call the computerPlay() so it set round1Answer
    then set this
document.getElementById("outcome").textContent = `You: ${userSelection} Computer: ${round1Answer}`;

then call playRound() function by the way you do not need to make it with parameters as it already has access to all the required data

  1. i will post the full answer at the end but try to solve it by yourself first

  2. try to use IDE or editor to help you fix the missing semicolon and any other issue that could happen in future

hope that help and have a nice day

const gameInputs = ['rock', 'paper', 'scissors'];
        let computerSel;
        let round1Answer;
        let userSelection;


        
        
                document.getElementById("btn1").addEventListener("click", () => {
                    userSelection = "rock";
       computerPlay();    
                  playRound(round1Answer, userSelection);
                });
                document.getElementById("btn2").addEventListener("click", () => {
                    userSelection = "paper";
                    computerPlay();
                  playRound(round1Answer, userSelection);
                });
                document.getElementById("btn3").addEventListener("click", () => {
                    userSelection = "scissors";
                 computerPlay();   
                  playRound(round1Answer, userSelection);
                });
                
            

            function computerPlay() {
                computerSel = Math.floor(Math.random() * gameInputs.length);
                round1Answer = (gameInputs[computerSel]);
                console.log((gameInputs[computerSel]) + " " + userSelection);
                
            }

           

            function playRound(round1Answer, userSelection) {
               document.getElementById("outcome").textContent = `You: ${userSelection} Computer: ${round1Answer}`;

                if (userSelection === 'rock' && round1Answer === 'scissors') {
                    alert('You WIN!');
                } else if (userSelection === 'rock' && round1Answer === 'rock') {
                    alert('It/s a tie!');
                } else if (userSelection === 'paper' && round1Answer === 'rock') {
                    alert('You WIN!');
                } else if (userSelection === 'paper' && round1Answer === 'paper') {
                    alert('It/s a tie!');
                } else if (userSelection === 'scissors' && round1Answer === 'paper') {
                    alert('You WIN!');
                } else if (userSelection === 'scissors' && round1Answer === 'scissors') {
                    alert('It/s a tie!');
                } else {
                    alert('You LOSE!');
                }
            }
            
    ```