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 trialluisgomez7
5,557 PointsProblems with objectives titled "Modifying Elements"
I'm pretty sure the answer to the first objective in the above link should be this:
const inputValue = document.querySelector('input');
But this is the error message I keep getting:
"Make sure that you get the value of the selected 'input' element."
However, I tested my answer by copying the html coding into a blank txt file and then converted to an html file. I then used the Google console to test my code and it worked!
Here's what happened:
const inputValue = document.querySelector('input');
console.log(inputValue);
<input type=ā"text" id=ā"linkText" value=ā"sample text">ā
What's going on here?
3 Answers
Steven Parker
231,261 PointsYour code is selecting the correct element, but the instructions ask you get the value of the selected 'element
So use the membership operator to access the value attribute:
const inputValue = document.querySelector('input').value;
// ^^^^^^ get the value
luisgomez7
5,557 PointsYour approach worked but this method wasn't taught in the instructional videos preceding these objectives. This was also the problem in the objectives I asked for previously. This is a nonsensical approach to instruction. I beginning to lose faith in this company.
luisgomez7
5,557 PointsThis looks much closer to what was taught. Thanks.
Steven Parker
231,261 PointsSteven Parker
231,261 PointsSorry if I caused any confusion, I optimized the solution to make a smaller change to your code.
Accessing element attributes is covered in the Change Element Attributes video. There's an example starting at time index 0:52 that sets the "type" value of an element. Here, we are getting instead of setting, and I skipped the creation of the intermediate variable since it isn't needed later. If you wanted to take that extra step, the challenge would also accept a solution using the intermediate variable exactly like was shown in the video example: