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

Brackets

Why Dave used the h2 and the variables names inside brackets at teh top of the js document in "The Story Maker Challenge"? Is that just for his organization or he intended to print that to the browser? If yes, what is the point of printing the same thing again using the command document.write? One more thing: if he used the h2 at the top of the tag just for his organization, that is not going to be visible to the user in the browser? I am really confused.

Thanks!

3 Answers

Tiffany White
Tiffany White
5,373 Points

Dave is just laying out what the outcome of the app should be. It's just for his organization, basically.

Thank you, Tiffany! It made sense after your second comment. I just do not know why he solves a challenge in a different way than the way he explained in the tutorials. Just makes everything more confusing than really is!

Tiffany White
Tiffany White
5,373 Points

Hey @brevans26, if I helped you, could you mark it as accepted? Thanks!

The fact of putting the content inside <h2> tags is irrelevant?

Tiffany White
Tiffany White
5,373 Points

In the beginning of the file, it is just a framework for what he wants to do.

In the main code, he assigns a string with an <h2> tag to sentence to be written on the screen.

// Assigns a number 2 heading and string to sentence
var sentence = "<h2>There once was a " + adjective;
// (...more code...)
// writes sentence to the screen by calling document.write
document.write(sentence);
// This will print the contents of sentence to the screen with a number 2 heading, or <h2>

I hope that makes sense.