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

Why is this happening? Not passing task 1

let linkName = document.getElementById("linkName"); let inputValue = linkName.value; let a = document.getElementById("link"); inputValue = a.value; So I have assigned the inputValue to something new. The content within the a but it seems to not like this. Why?

app.js
let linkName = document.getElementById("linkName");
let inputValue = linkName.value;
let a = document.getElementById("link");
 inputValue = a.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

Jose Soto
Jose Soto
23,407 Points

Try setting the element value into the inputValue variable directly:

let inputValue = document.getElementById("linkName").value;

For step 2, you'll want to set the element's innerHTML value to inputValue.

let inputValue = document.querySelector("#linkName").value; inputValue = document.querySelector("#link").innerHTML; This is still not passing the first task. This is really stupid! Why would they ask me to redefine the variable inputValue but then expect the variable to still be defined as in the previous task?!!! I've been stuck on this so long! Dude, what am I doing wrong?

Jose Soto
Jose Soto
23,407 Points

Try this

let inputValue = document.querySelector("#linkName").value;
document.querySelector("#link").innerHTML = inputValue;

Thank YOU JOSE! That worked, that is the stupidest task that I have encountered as of yet. Can you explain why they are asking this and also why that works when the directions clearly state "store the.... in the variable inputValue" when it passes if you store the value of value of inputValue in the #link element? This doesn't make sense to me, since one is a link and one is a description, why would you want to store that value in the link?