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

What is wrong with this code?

I can getting this error but it doesn't explain anything: Bummer: There was an error with your code: TypeError: 'undefined' is not a function (evaluating 'document.getElementbyId('sayPhrase')')

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>

2 Answers

Jonas Jensen
Jonas Jensen
10,963 Points

The "document.getElementbyId" should be "document.getElementById" so it is just the b that should be uppercase instead of lowercase.

Darrin Spell Jr
Darrin Spell Jr
Full Stack JavaScript Techdegree Student 10,303 Points

When using a method in JS you'll need to use camel casing. EX: camelCasingLooksLikeThis In your code you just missed a camelCase 'getElementbyID' should be 'getElementById'