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
nick beck3,625 Points
how come you don't the parentheses, in the first sentence variable?
i notice that on the first sentence variable, there are no parentheses used. why not ?
Sean T. Unwin28,690 Points
If you are referring to the variable,
var sentence = '<h2>There once was a " + adjective;
it is because we don't put quotes around variables and since
adjective, in this case, is a String and so is
I hope that my wording was not too confusing.
In simple terms to what Sean is saying.
var adjective = prompt ('Please type an adjective'); Here we are asking the person to type the adjective variable.
var sentence = "<h2>There once was a " + adjective; Here is a new variable named sentence which adds the first string "<h2>There once was a " to the variable adjective which is not a string. I look back and review the "String and Numbers" video.
Regarding the parentheses it doesn't matter what you use whether it be '' or "" You just need to be consistent and use them appropriately.
Hope that helps!
Samantha AtkinsonFront End Web Development Techdegree Student 36,955 Points
The reason why there are no parentheses for the variable named sentence is because the value is simply a string with no command or methods attach to it and the results from your previous variable named adjective prompt added on. Parentheses are used for methods for example: alert('You have done well!'); or document.write ('Have a nice day');. Methods are actions, alert opens a dialog box in your browser and document.writes writes text to your web page.
Hope this makes it a little clearer.