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

Jason Ngo
Jason Ngo
6,947 Points

Why am I getting a typeError?

Why am I getting a typeError of undefined?

let button = document.getElementbyId('sayPhrase');
let 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>

3 Answers

Colton Ehrman
Colton Ehrman
242 Points

You have an undefined variable declaration let input; and then you are trying to call alert(input.value)

Jason Ngo
Jason Ngo
6,947 Points

Thanks, I was able to figure it out!