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 exercise

Hello, the task is:

  1. Store the value of the text input element in the variable inputValue. (If you need a refresher on getting the value of a text input, this video from the previous section demonstrates how.)

let inputValue = document.querySelector('input').value;

  1. Set the text content of the a tag to be the value stored in the variable inputValue.

inputValue = document.querySelector('a').textContent;

The first task is ok, the second one gives me an error that the first task is no longer passing, and i dont know why, im pretty sure that I did correctly. Thank you

P.S. There are only 1 input tag and 1 a tag in the HTML, sorry I didn't add it

3 Answers

Zack Lee
PLUS
Zack Lee
Courses Plus Student 17,662 Points

document.querySelector('a').textContent = inputValue;

they expression needs to be revered. the way you wrote it assigns the textContent of 'a' to inputValue.

watch how you order things. left of the '=' is always the variable you are modifying.

inputValue = document.querySelector('input').value;

The text content of the tag to which the value stored in the inputValue variable is:

document.querySelector('a').textContent = inputValue;