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

I cant make a variable hold two values at the same time!

This code challenge asks me to make inputValue equal the value of the input tag, which I can do easily, but then it says to make the link stored in the a tag the value of input value, and when I do that it says "Looks like task one is no longer passing". I cant find a way around it!

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

Hi Peter,

The second task says, "Set the text content of the a tag to be the value stored in the variable inputValue."

Your code would look like this:

let tinput = document.getElementById("linkName"); 
let a = document.getElementById("link"); 
let inputValue = tinput.value; 
a.textContent = inputValue; 

The 4th line is what you're missing. You're setting the textContent of a (a tag) to be the value you stored in inputValue.

Cheers,

Yeah, that makes sense now that you point it out, Thanks :)

Oliver Duncan
Oliver Duncan
16,642 Points

I think (my payment is overdue, I can't see the challenge!) what they want is for you to take inputValue and make the inner text of the link read as that value. So something like this:

let tinput = document.getElementById("linkName");
let a = document.getElementById("link");
let inputValue = tinput.value;
a.innerText = inputValue;

Your concept was right, but I was supposed to set it to textContent instead of innerText, Thanks for your help though!

Dan Noyes
Dan Noyes
6,183 Points

I was able to get both tasks to pass with these two lines of code:

let inputValue = linkName.value;
link.textContent = inputValue;