1

I'm trying to retun the button i pressed i can console.log it but it can't return

const playerSelect = () => {

  RPS = document.querySelectorAll(".rpsButton")
  RPS.forEach(i => {

     i.onclick = () => {

        return i.value
     } 
  })
}

return it to here and get comparison

const compare = (playerChoise()) => 
{
  if (getComputerChoice() == "rock" && playerChoise == "paper")
  {
    score++
  }
}
<div class="buttons">
    <button class="rpsButton" value="Rock">✊</button>
    <button class="rpsButton" value="Paper"></button>
    <button class="rpsButton" value="Scissors">✌</button>
</div>
NTZ
  • 21
  • 3
  • 3
    Return it … to where? – Quentin Oct 07 '22 at 20:30
  • @danh — `i` and `event.target` will have the same value in this case. – Quentin Oct 07 '22 at 20:32
  • @DanielBlack — Those will give the same value as `i` in this case. The question is about **returning** a value from an event handler. – Quentin Oct 07 '22 at 20:32
  • @Quentin - good point, and yeah, return it to where? – danh Oct 07 '22 at 20:33
  • I think they want to do something like `const result = playerSelect();` and assign the value generated by the event listener attached by `playerSelect` to `result`. – Quentin Oct 07 '22 at 20:35
  • [This is a dupe more or less](https://stackoverflow.com/questions/73977396/cannot-return-the-value-from-button/73977703). – Andy Oct 07 '22 at 20:58

0 Answers0