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 trialRan Wang
Full Stack JavaScript Techdegree Graduate 32,191 PointsWhy my code does not work?
When I write like this:
let inputValue = document.querySelector('#linkName').value; inputValue = document.querySelector('a').textContent;
It did not work, but when I reverse the order before and after the '=':
document.querySelector('link').textContent = inputValue;
it worked, can anyone tell me why? For me, the 2 methods are the same.
let inputValue = document.querySelector('#linkName').value;
inputValue = document.querySelector('#link').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
Steven Parker
231,261 PointsThe assignment operator ("=") always works right-to-left. The value of the term on the right side is stored in the location referenced on the left side. So when you swap the sides, it's not the same. Only one way is correct.
Ran Wang
Full Stack JavaScript Techdegree Graduate 32,191 PointsRan Wang
Full Stack JavaScript Techdegree Graduate 32,191 Pointsthanks Steven, but in the code below shows the opposite: value at right is assigned to the left (listDiv's display). Can you help me to understand why in the code below it is legit, but not in the code above?
Steven Parker
231,261 PointsSteven Parker
231,261 PointsWe are saying the same thing: the value at right is assigned to the left.
What's wrong with the code above is that it is putting the "textContent" into the "inputValue", but the instructions say to put the "inputValue" into the "textContent" instead;
Ran Wang
Full Stack JavaScript Techdegree Graduate 32,191 PointsRan Wang
Full Stack JavaScript Techdegree Graduate 32,191 PointsThank you! very clearly explained!