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 trialRobert O'Toole
6,366 Pointsdoes anyone find the need for (' ') vs ( ) somewhat ridiculous ?
the way .appendchild(string) doesnt require quotations in the string but then things like createElement('string') do require quotations... then getElementsbyTagName requires capitalization and quotations ('STRING') but then query selectors require ('string'). is this just a shortcoming of the language? is this me not understanding something that should be more consistent in my thought process?
its honestly driving me nuts and its usually the only mistake i make on this stuff. does anyone have a clear and concise way of learning this? or is this just something i have to constantly struggle with and google
hopefully you guys understand what im saying here. partly venting partly asking for help
2 Answers
Steven Parker
231,248 PointsIt sounds like you may be confusing string literals with string variables. String literals are always enclosed in quotes, and they represent the characters that are between the quotes (and can never change).
On the other hand, variable names are never enclosed in quotes, and what they represent depends on what they were most recently assigned with (which can be changed at any time).
A function that takes a string argument (like appendchild) can be passed either a variable or literal. Here's two examples:
someElement.appendChild(MyStringVariable); // passing a string variable argument
someElement.appendChild("<button>Stop</button>"); // passing a string literal argument
Finally, tag names are stored internally in upper case for legacy reasons, but they are an exception.
Robert O'Toole
6,366 Pointsthank you so much I think I overlooked this... I was wondering why this all seemed so inconsistent for me and I knew there was a proper method to passing strings! thanks again!