Q: Combining HTML onclick functions from two buttons? I am coding a choose your own adventure game, and I currently have two buttons on the page: one that passes variables from HTML to JavaScript, and one that calls the JavaScript function to start the game. They both work fine on their own, but I want to merge them into one button that performs both functions. Here's the code:
  <button onclick="add(document.getElementById('FirstName').value, document.getElementById('LastName').value)">Add</button>

   <button onclick="pirates();"> Ready to Play? </button>   


A: Why not just add add(document.getElementById('FirstName').value, document.getElementById('LastName').value) To the beginning of your pirates() function, then clicking the 'Ready to Play?' button would do both things.

A: <script>
  function pirates(){
    add(
      document.getElementById('FirstName').value,
      document.getElementById('LastName').value
    )
  }
</script>
<button onclick="pirates();"> Ready to Play? </button> 


A: Assuming you add the id btn to your button, this script will get the values and pass them to pirates().
var firstName;
var lastName

btn = document.getElementById('btn');

btn.onclick = function() {
  firstName = document.getElementById('FirstName').value;
  lastName = document.getElementById('LastName').value;
  pirates(firstName, lastName);
};

