Learn Recursion by Building a Decimal to Binary Converter - Step 104

Tell us what’s happening:

Hello, I’m stuck here, not sure how to chain .textContent to the .getElementById() method.

Also, It would be a good feature to be able to move this Ask for Help pop up box in case we need to see something in the background without having to close it and restart our help query. Thanks, I’m really enjoying this course!

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

    msg = document.textContent.getElementById(obj.inputVal);

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36

Challenge Information:

Learn Recursion by Building a Decimal to Binary Converter - Step 104

That not the correct way chain a value. You need to chain it in the end of getElementById()

1 Like

Hey.

You should use .textContent at the end of that expression. First you grab the element by document.getElementById(), then you want to access textContent of it.

And also do not forget the add obj. before the msg value. Because you need to access current object’s msg value.

3 Likes

Thanks Hasan! I got it to work but I’m not sure what’s the difference between
document.getElementById(obj.inputVal).textContent = obj.msg and
obj.msg = document.getElementById(obj.inputVal).textContent

Why does the first line work but the second doesn’t? What I mean is why are they not the same thing when assigning something…thanks!

1 Like

The first line updates the DOM element’s content based on obj.msg.
The second line retrieves the DOM element’s content and saves it in obj.msg.

2 Likes