title: How can I wait for a click to be executed?
body: <p>I am trying to figure out how I can update the playerValue for my Rock Scissor Paper game. I have a function that registers a button click and should then update the playerValue accordingly(1,2 or three depending on which button was clicked). The problem is, when I call the function, the playerValue remains 0 and I don't know what I need to change to fix that. playerValue itself is defined at the very beginning of my file. It starts out as 0.</p>
  <p>Here is my JavaScript code(or at least the relevant part of it):</p>
  <pre><code>//register button click and:
  function player_choose_value(){
      //check which button has been clicked -&gt; rock 1, scissor 2 or paper 3
      btnRock.addEventListener(&quot;click&quot;, () =&gt;{
          playerValue = 1;
      });
  
      btnScissor.addEventListener(&quot;click&quot;, () =&gt;{
          playerValue = 2;
      });
      
      btnPaper.addEventListener(&quot;click&quot;, () =&gt;{
          playerValue = 3;
      });
  }
  </code></pre>
  <p>This here is where the playerValue is meant to be used. The playerValue is always 0. I think that is because the player_choose_value() function does not wait for the click event to happen. So the function is executed but the user does not have the chance to actually click a button, so it stays 0:</p>
  <pre><code>function play_round(){
      let computerValue = computer_choose_value();
      player_choose_value();//is always zero
      console.log(playerValue);
      won_tie_lost(computerValue, playerValue);
  }
  </code></pre>
  <p>I was wondering how I could add a &quot;wait for one of the three buttons to be clicked&quot; functionality?</p>