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')')

var button = document.getElementbyId('sayPhrase');
var input;

button.addEventListener('click', () => {
<!DOCTYPE html>
    <title>Phrase Sayer</title>
    <p><input type="text" id="phraseText"></p>
    <p><button id="sayPhrase">Say Phrase</button></p>
    <script src="js/app.js"></script>

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.

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'