Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Variable Challenge : issue with previewing the page from the workspace.

Hello everyone,

I encounter a difficulty in this exercise: the preview button allows me to open a webpage displaying the HTML elements (entitled "The Story Maker"). However, none of the code I wrote in story.js is being read. Even erasing the code and simply entering an alert(Test); doesn't bring any change to the webpage.

So far, I double-checked that: -The script is saved under the name story.js. -The HTML page refers to story.js. -All browser historics have been deleted.

Here is the snapshot: https://w.trhou.se/zy0y43hdno

I am using Chrome in Windows 10.

Thanks in advance for your help.

2 Answers

Your script fails because the single (') and double quotes (") don't allow multiline sentences.

You can do multiline sentences with backticks (\)`.

With backticks you can also interpolate variables like so

let fullStory = `<p>Once upon a time, there was a  ${noun}. Its name was ${firstName}. It went to ${verb} around ${place}, didn't like it, and decided it would never ${verb} ever again. So, it left ${place} never to come back. But another story tells that ${firstName} was proven wrong...
THE END.</p>`;

Note that seperate from this problem there's another problem in the way that you try to print.document(fullStory);, this won't prevent the rest of the script to run (unlike the above error), but it won't update the HTML either. (Try it and you'll see, it will prompt you for input, and alert you that the story is done, but it won't print it to the document.

To print it to the document, use document.write(fullStory);

I see.

Thanks a lot for the quick and detailed answer! This really helps.

I'll try to extract these and test them in Atom, just to see what comes out (with a corrected version of course).