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 trialluisgomez7
5,557 PointsI'm having trouble answering this question from the video series titled "Javascript and the DOM."
Here's the link for the question from the challenge: https://teamtreehouse.com/library/javascript-and-the-dom-3/getting-a-handle-on-the-dom/select-by-id
This is the question: "Declare a variable named button. Assign the variable the <button> element with the ID btn-phrase. Use the method that returns an element matching the specified ID."
// Complete the challenge by writing JavaScript below
let button = button.getElementById();
button.addEventListener('click', () => {
alert(input.value);
});
My answer, as you can see above is "let button = button.getElementById();" However, the website keeps telling me button is not defined when I have clearly defined it. What am I doing wrong?
3 Answers
luisgomez7
5,557 PointsMy method produced a correct answer message from the website. Perhaps you're referring to a different question.
jb30
44,806 PointsTry passing the id btn-phrase
to button.getElementById()
.
luisgomez7
5,557 PointsUnfortunately, that didn't work.
luisgomez7
5,557 PointsNever mind. I figured it out.
luisgomez7
5,557 PointsSaim: The correct answer is let listItems = document.getElementsByTagName('li');
. I've discovered using "const" instead of "let" works as well.
Saim Diaz
10,095 PointsThank you for responding Luis. However, aren't we supposed to declare a variable with the name button? And aren't we supposed to use a method that returns an ID? On mine I have: const button = document.getElementByID('btn-phrase'); but it says that document.getElementByID isn't a function. Not sure what I'm doing wrong.
jb30
44,806 PointsTry changing document.getElementByID
to document.getElementById
with a lowercase d
in Id
.
Saim Diaz
10,095 PointsThank you jb30! That's exactly what was wrong. Appreciate the help. And no worries Luis, I think we were talking about a different question as well. Thanks for the help anyways!
Saim Diaz
10,095 PointsSaim Diaz
10,095 PointsI am also having trouble with this quiz. Can someone help me with the answer?