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

Natasha Harrington
Natasha Harrington
9,723 Points

I can't figure out what's wrong with this code.

I can not figure out what is wrong with this code. It tells me undefined is not a function?

js/app.js
var button = document.getElementByID('sayPhrase');
var input;

button.addEventListener('click', () => {
  alert(input.value);
});
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