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 trialAndrew Phythian
19,747 PointsWhy is inputValue = * incorrect, but * = inputValue is correct
To explain, in the second question the following code
let inputValue = document.getElementById('linkName').value;
inputValue = document.getElementById('link').textContent;
is incorrect, but
let inputValue = document.getElementById('linkName').value;
document.getElementById('link').textContent = inputValue;
works fine.
In other words, the placement of 'inputValue' has to be at the end of the statement?
1 Answer
Kristiana Georgieva
14,595 PointsHi! Here's my take on it.
let inputValue = document.getElementById('linkName').value;
// the variable 'inputValue ' is equal to the element with ID linkName.
inputValue = document.getElementById('link').textContent;
// here, you are again saying that the variable 'inputValue '
// should be equal to an entirely different thing
// (the text content of the element with ID link). It contradicts the line of code above.
While in the second code:
let inputValue = document.getElementById('linkName').value;
// the variable 'inputValue ' is equal to element with ID linkName.
document.getElementById('link').textContent = inputValue;
// the text content of the element with ID link is equal to the content of the 'inputValue ' variable
Hope it makes sense. Or maybe someone could explain it better :)
Good luck!
Andrew Phythian
19,747 PointsThanks for the reply. I was aware of the issue of 'scope' but had never considered that the placement of inputValue in the statement was important.
Andrew Phythian
19,747 PointsAndrew Phythian
19,747 PointsUnless I am mistaken, after a bit of experimentation it seems particular to this challenge. In the console if I type
the console outputs 15.
Changing a
outputs 25 just fine.