Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
Eventlistener throws error when parsing function

I have just started programming and this event handler isn't working.

Uncaught TypeError: Failed to execute 'addEventListener' on 'EventTarget': parameter 2 is not of type 'Object'. at script.js:51:33

document.getElementById("rock").addEventListener("click", playRound("rock", computerPlay()));

Here is the full (not finished) code:

const answers = ["rock", "paper", "scissors"];
let playerScore = 0;
let computerScore = 0;

function computerPlay() {
    return answers[Math.floor(Math.random() * answers.length)];
}

function playRound(playerSelection, computerSelection) {
    playerSelection =  playerSelection.toLowerCase();

    if (playerSelection == computerSelection) {
        return ("Tie!");
    }
    else {
        switch (playerSelection) {
        case "rock":
            if (computerSelection == "paper" ) {
                computerScore++;
                return ("You lost! " + computerSelection + " beats " + playerSelection);
            }
            else {
                playerScore++;
                return ("You won! " + playerSelection + " beats " + computerSelection);
            }
        case "paper":
            if (computerSelection == "scissors" ) {
                computerScore++;
                return ("You lost! " + computerSelection + " beats " + playerSelection);
            }
            else {
                playerScore++;
                return ("You won! " + playerSelection + " beats " + computerSelection);
            }
        case "scissors":
            if (computerSelection == "rock" ) {
                computerScore++;
                return ("You lost! " + computerSelection + " beats " + playerSelection);
            }
            else {
                playerScore++;
                return ("You won! " + playerSelection + " beats " + computerSelection);
            }
        }
    }
}

console.log(typeof(computerPlay));


document.getElementById("rock").addEventListener("click", playRound("rock", computerPlay()));
document.getElementById("paper").addEventListener("click", playRound("paper", computerPlay()));
document.getElementById("scissors").addEventListener("click", playRound("scissors", computerPlay()));

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!