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

Modifying Elements Code Challenge Task 2 - variable question

I'm not sure if I understand what I'm suppose to be doing within task two. If I'm using the same variable I'm doing something wrong or I don't understand the context. If I try and change the variable after it's been declared with document.getElementsByTagName() function, I get an error trying to catch the <a> tag text. If I just try and use the <a> tag during the variable declaration, I cause an issue with task one.

So I must not understand exactly what is supposed to happen here. Or if it's suppose to be a different variable name?

app.js
let inputValue = document.getElementById('linkName').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>

3 Answers

Steven Parker
Steven Parker
231,261 Points

Task 2 is sort of like the opposite of task 1. In task 1 you have taken a value from an element on the page and put it into a variable.

In task 2, you will use the variable (the same one) and put the value into a different page element. So the code to find the correct element and property will be a bit different, and will be on the other side of the assignment.

Perfect! Thanks for the explanation. I think I was just reading it all wrong. With the context that you framed it with, it helps a ton.

Again, thanks! I really appreciate it.

Steven Parker
Steven Parker
231,261 Points

Start a fresh question (preferably using the "get help" button) and include a description of your issue(s). The system should automatically include your task code and a link to the challenge.