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 trialAhmed El-Kordy
3,565 Pointsvariable u separated "const main = document.querySelector('main'); and at the end u did main.InnerHTML = `whatever`
Ok so i know i am still at the beginning of my journey, but i really need to ask about something in your solution code,
Why did u separate this code
<code>
const main = document.querySelector('main');
main.InnerHTML = whatever
;
</pre></code>
Q- Why didn't you write the whole line once at the end like:
<code>
const main = document.querySelector('main') = <h2>whatever ${correct} out of 5</h2>.
<p>Crown : ${rank}</p>
;
</code>
the confusing part for me as a newbie is, it looks like u some how concatenate both line in away that doesn't make sense to me at the moment can you elaborate on that please.
aside note for teamtreehouse:
I like the new pushed update for the javascript basics materials, but i thing the practice at end stage is not relative to the materials you providing at the moment, or maybe i am just to dumb not sure let me know.
thatks
2 Answers
Steven Parker
231,236 PointsFirst, the forum doesn't respond to embedded HTML tags. To get code blocks you must use Markdown formatting (as I have done below).
Then, your second example (with the two assignments in the same statement) is not proper syntax, but it is possible to perform the select and the assignment in one statement, and you skip the creation of the "main" variable:
document.querySelector('main').innerHTML = "whatever";
Unless "main" gets used again later, it was probably broken into two steps to make the total operation easier to understand.
And lastly, you can make suggestions directly to the staff as described on the Support page.
Ahmed El-Kordy
3,565 PointsFirst of all thank you for your answer, but can u explain more why its not proper syntax ?
Steven Parker
231,236 PointsSee the comment added to my answer.
Steven Parker
231,236 PointsSteven Parker
231,236 PointsJavaScript doesn't allow you to directly assign to the result of calling a method:
document.querySelector('main') = "whatever"; // "invalid left-hand side in assignment" error
Besides, that selector method returns a reference to an element, you wouldn't want to replace it with a string.
But, as shown in my other example, you can use that reference to access a property and then assign to that property.