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 trialmichael williams
19,492 Pointscode challenge selecting by id I am not quite sure what the instructions are asking in task 1.
Right now I have:
<code>
let button;
let input;
const sayPhrase = document.getElementById('sayPhrase');
button.addEventListener('click', () => {
sayPhrase.value;
});
</code>
But I know something is missing or I am way off.
let button;
let input;
const sayPhrase = document.getElementById('sayPhrase');
button.addEventListener('click', () => {
sayPhrase.value;
});
<!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
Steven Parker
231,271 PointsYou have the right value, but put it in the wrong variable.
The instructions say, "There is a variable named button in app.js. Set its value to contain a reference to the button element in index.html with the ID of sayPhrase."
You got a reference to the correct button, but instead of putting it in button, you put it in a new variable named sayPhrase.
Jason Anders
Treehouse Moderator 145,860 PointsHey Michael,
You have the right syntax for selecting the id
, but you aren't assigning it to the correct variable.
The challenge did not ask you to create the const sayPhrase ...
as you have. It wants the result of the selection to be assigned to the button
variable. So, you need to delete the variable you created and move the selector to the button
.
Keep in mind for future challenges that the instructions are very specific and very picky. If you add something that wasn't asked for, deleted something that you weren't told to, or even forget a period in a string... the challenge will throw a Bummer!
.
let button = document.getElementById('sayPhrase');;
let input;
button.addEventListener('click', () => {
alert(input.value);
});
Keep Coding!
michael williams
19,492 Pointsthank you for your help!!
Jason Anders
Treehouse Moderator 145,860 PointsJason Anders
Treehouse Moderator 145,860 PointsSteven Parker
Your typing speed seems to be a bit faster than mine. LOL.
Steven Parker
231,271 PointsSteven Parker
231,271 PointsJason Anders — or maybe it's the time difference between just answering the question and writing an elegant tutorial.
michael williams
19,492 Pointsmichael williams
19,492 Pointsthanks steven! i appreciate it!