JavaScript JavaScript and the DOM Getting a Handle on the DOM Selecting by Id

no comprendo muchacho

i do not understand how assign the button to the variable

js/app.js
var button;
var input;

button.addEventListener('click', () => {
  alert(input.value);
});

var button = document.getElementById("sayPhrase");
index.html
<!DOCTYPE html>
<html>
  <head>
    <title>Phrase Sayer</title>
  </head>
  <body>
    <p><input type="text" id="phraseText"></p>
    <p><button id="sayPhrase">Say Phrase</button></p>
    <script src="js/app.js"></script>
  </body>
</html>

1 Answer

Steven Parker
Steven Parker
173,603 Points

It looks like you have the right code, but in the wrong place.

Just move your initialization up to the top line to replace the simple declaration initially provided.