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!

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 trial

JavaScript JavaScript and the DOM (Retiring) Making Changes to the DOM Modifying Elements

Need help completing this challenge

Tried playing around with it and it wont work. I tried 'a.link' also

var inputValue = document.getElementById('linkName').value;
inputValue = document.getElementById('link').textContent;
<!DOCTYPE html>
        <title>DOM Manipulation</title>
    <link rel="stylesheet" href="style.css" />
        <div id="content">
            <label>Link Name:</label>
            <input type="text" id="linkName">
            <a id="link" href="https://teamtreehouse.com"></a>
        <script src="app.js"></script>

1 Answer

Cameron Childres
Cameron Childres
11,815 Points

Hi Nas,

You're incredibly close -- the only issue is the order in your assignment on the second line.

The left side of the assignment operator is what a value will be assigned to, the right side is the value being assigned. To give document.getElementById('link').textContent the value from inputValue you just need to swap around the order:

document.getElementById('link').textContent = inputValue;

This helped thank you. I don't understand what's the difference between putting the variable on the other side, does it make that much of a difference?

Cameron Childres
Cameron Childres
11,815 Points

It certainly does! You can think of the left side as receiving the value and the right side as giving the value.

As a little demonstration try this out in your console:

let y;
4 = y; // produces error: Invalid left-hand side in assignment
console.log(y); // y is undefined

This won't work as it is trying to change the value of the number 4 to y (since y is on the right side).
If we switch it around then 4 is given to y, which works:

let y;
y = 4;
console.log(y); // prints 4 to console

As another example, try to figure out what will be logged to the console here:

let x = "blue";
let y = "red";
x = y;

I see, the left is for receiving the right is for giving. For the example you showed me on the bottom you wanted the variable x to show first so blue would show up first. Then below that red would show up. Where you confused me is "x=y" wouldn't that show an error? I'm confused as to how that works

Cameron Childres
Cameron Childres
11,815 Points

Just a bit of a brain teaser there. The "x=y" part is key: x is going to receive the value given to it by y. In other words, x is being reassigned to have the value of y.

Try the code out in your console to see the result or let me know if you'd like the answer.

I just applied that code in the console and it was just like you said x is now y so both show "red" when i logged it in the console. I see now, thank you for the help!.