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

JavaScript JavaScript Basics (Retired) Storing and Tracking Information with Variables The Variable Challenge Solution

nick beck
nick beck
3,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 ?

3 Answers

Sean T. Unwin
Sean T. Unwin
28,690 Points

If you are referring to the variable, adjective, in:

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 sentence, essentially the quotes are put around it by way of the plus ('+') operator. This is JavaScript saying it will add, or otherwise attach, this variable to this String that has been started with plain text.

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 Atkinson
Samantha Atkinson
Front End Web Development Techdegree Student 36,955 Points

Hi Nick,

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.