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,277 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!

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

Tiffany White
Tiffany White
5,277 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.

Tiffany White
Tiffany White
5,277 Points

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