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 trialIan Verheyden
1,467 PointsI'm really not sure what the problem is here. Please help!
I'm bugging out and cannot seem to figure out what the problem is. Not sure I understand the wording of the problem being asked.
const inputValue = document.querySelector('body div input').value;
const aTag = document.innerHTML('body div a');
inputValue.value = aTag.textContent;
<!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>
1 Answer
crosscheckking
25,155 PointsYou have two mistakes in your initial code which you might've found already since it's been a while since you posted. The fist mistake is that you accidentally used innerHTML instead of querySelector. Remember, innerHTML allows you to put HTML code inside of an element. querySelector is what you need to store the first matching element object (like you used in the first step correctly). The second mistake was just an understanding mistake. The question wanted you to store the value of inputValue inside aTag's textContent. You will not need to use ".value" because you already stored the value of the input element in the first line, so the variable only contains a string of the value. Here is what the code should look like:
const inputValue = document.querySelector('body div input').value;
const aTag = document.querySelector('body div a');
aTag.textContent = inputValue;
crosscheckking
25,155 Pointscrosscheckking
25,155 PointsUpvotes and Best Answer are always appreciated if this correctly answers all of your questions. I can always try to provide more help if needed.
Ian Verheyden
1,467 PointsIan Verheyden
1,467 PointsThank you for your help John. Could you please explain why the third line of this code is...
aTag.textContent = inputValut;
...as opposed to:inputValue = aTag.textContent
...which returns an error saying that inputValue is read only. I understand that it is supposed to be read only (because its a constant) in the second situation, but then why can it be overwritten in the first?crosscheckking
25,155 Pointscrosscheckking
25,155 PointsIt's because
const
doesn't allow you to change the value of the variable. So if the value of the input element that we originally stored in theinputValue
variable was say 12 as an example, then we couldn't write over it with a new value such as whatever was the textContent of aTag. But that is not the only reason it wouldn't work. Even if you usedlet
to declare the variable, the challenge would still throw an error because the only way to assign a value to a variable, or in this casea.TagContext
, is to place the variable on the left side of the assignment operator=
. Since it wanted us to assign the value to 'a.TagContext', we needed to put that on the left side of the equation and then the value (inputValue
) on the right side of the equation because it stores the value we want to store ina.tagContent
. Hope this helps.