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 trial

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

yousif alyousif
yousif alyousif
2,322 Points

can any one please explain to me this challenge in JavaScript?

the Challenge Task says: Set the text content of the a tag to be the value stored in the variable inputValue.

I did the same as I was advised for the first part of the challenge but it did not pass?! I know it is the same variable name but isn't the new one replacing the old one if I am using the (let) !!! I really do not know what I am doing wrong!

app.js
let inputValue = document.getElementById('linkName').value;
let inputValue = document.getElementById('link').value;
index.html
<!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>
yousif alyousif
yousif alyousif
2,322 Points

just to add I think they mean <a> so it is not a normal unless one of the advisors can explain what they meant exactly coz it kept giving me an error

3 Answers

Dane Parchment
MOD
Dane Parchment
Treehouse Moderator 11,076 Points

Here is what you need to do:

let inputValue = document.getElementById('linkName').value;
let aContent = document.getElementById('link').textContent = inputValue;

The challenge is asking you to set the textContent of the a link, not it's value, so I highly recommend that you re-watch the video that covers this topic (the one before the challenge).

Next, don't create variables with the same name within the same global space, that is both bad programming practices, and in every language I know it will lead to Syntax errors (using let won't change that), as you are effectively trying to open up a new space for memory in your RAM that is already in use!

yousif alyousif
yousif alyousif
2,322 Points

Thanks for the nice explanation

Vic Mercier
Vic Mercier
3,276 Points

There different way to do that: First you need to select your element which is your input : const myInput = document.getElementById("linkName"); const myInputValue = myInput.value;

yousif alyousif
yousif alyousif
2,322 Points

I think the problem is that they want me to <a> tag in HTML to me stored on the same variable ?! because the code you advised me with did not pass !

Vic Mercier
Vic Mercier
3,276 Points

let a = document.getElementById("link"); let aContext = a.textContent;

yousif alyousif
yousif alyousif
2,322 Points

sadly it still did not work because the description says: Set the text content of the <a> tag to be the value stored in the variable inputValue thus i think the variable should be the same!

Dane Parchment
Dane Parchment
Treehouse Moderator 11,076 Points

Though Vic's answer won't pass you the challenge it is how you would go about solving the problem!