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 trialY B
14,136 PointsJS and the DOM - setting text content challenge fail
I can't seem to pass this challenge for some reason? Strangely the question asks to reuse the same variable name from the first challenge which could be the issue?
<!DOCTYPE html>
<html>
<head>
<title>DOM Manipulation</title>
</head>
<link rel="stylesheet" href="style.css" />
<body>
<div id="content">
<label>Link Name:</label>
<input type="text" id="linkName">
<a id="link" href="https://teamtreehouse.com"></a>
</div>
<script src="app.js"></script>
</body>
</html>
let linkName = document.getElementById('linkName').value;
linkName = document.getElementsByTagName('a').textContent;
Update
let linkName = document.getElementById('linkName').value;
const anchor = document.getElementsByTagName('a');
anchor.textContent = linkName;
1 Answer
Steven Parker
231,248 PointsYour assignment appears to be reversed.
The challenge says to: "Set the text content of the a
tag to be the value stored in the variable linkName
." But the code above is just changing the value in linkName.
Y B
14,136 PointsY B
14,136 PointsHmmm sorry not understanding your comment here. So I should reassign
linkName
by using:let linkName = document.getElementById('linkName').value; let linkName = document.getElementsByTagName('a').textContent;
Steven Parker
231,248 PointsSteven Parker
231,248 PointsYou should not change linkName at all for task 2.
The challenge tells you to give the value you already have stored in linkName to a document element. So the assignment you have now appears to have the left and right sides reversed.
Y B
14,136 PointsY B
14,136 Pointsi'm still not getting what's required here. I've updated my code but that still doesn't pass for some reason?
Steven Parker
231,248 PointsSteven Parker
231,248 PointsHas the challenge changed since you first asked?
It seems like the instructions are now asking for a different variable name! So task 1 now says, "Store the value of the text input element in the variable
inputValue
." So on line 1 you'll need change linkName to inputValue. You'll need to do the same on line 3 when you get to task 2.But you have another problem using getElementsByTagName. That returns an element collection, not a single element, so it would have no *textContent * property. But if you look at the HTML, you'll see that anchor also has an
id
property so you could select it the same way you selected the input element.Y B
14,136 PointsY B
14,136 PointsWhoops! Thanks