Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript and the DOM (Retiring) Getting a Handle on the DOM Selecting by Id

Randell Purington
Randell Purington
9,992 Points

I could use so help, please

I looked this question up in the community and I used the help from the answers provided but I can not seem to get it correct.

the code I thought would work is the code below. This isn't correct so I am lost. let button = document.getElementById("sayPhrase"); console.log(button);

js/app.js
let button;
let 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

Hi Randell, the challenge just wants you to use the button and input variables to select an element by its ID. So for example, in the first part of the challenge, it is looking for the following:

let button = document.getElementById('sayPhrase'); let input;

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

Based on this, try to solve the last part of the challenge!

Randell Purington
Randell Purington
9,992 Points

Thank you for the response but I am not understanding it even with your help, going back and reviewing the videos and my notes. I am not sure if there is a bug or if I am missing something to cause a syntax error.

What error are you getting, and were you able to complete the first part of the challenge?

let button = document.getElementById('sayPhrase'); 

let input;

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