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

luiscampos3
luiscampos3
4,904 Points

Story maker Exercise <h2>

This program worked fine under the treehouse console but when I copied the exercise into my computer's text editor (atom) and now JavaScript doesn't want to run. I used the development tools and this shows up: Uncaught SyntaxError: Unexpected token ILLEGAL. I checked the js and html code for errors.

this is the line error: "<h2>There once was a [adj] programmer who wanted to use JavaScript to [verb] the [noun]. </h2>"

Is there a different way you can start the program instead of using this statement?

Keith Greatz
Keith Greatz
4,377 Points

In your developer tools it shows what line causes the error, can you post that Line? not sure if i can help but I have done tutorial.

If you watch the vid to the side of this forum Called tips for asking questions, it details how to post your code well also.

Keiffy101

Benjamin Payne
Benjamin Payne
8,142 Points

Hey Luis,

The [adj] syntax is incorrect. In order to use the variable var adj; in the string you would need to do it like this.

var adj = 'brave';
var verb = 'change';
var noun = 'world';

var story = "There once was a " + adj + "brave programmer who wanted to use JavaScript to " + verb + " the " + noun + ".";
Philip Condon
Philip Condon
8,605 Points

if you are referring to the "There once was a [adj] programmer who wanted to use JavaScript to [verb] the [noun]. " that Dave wrote before declaring the variables he simply wrote that so he knew what he was about to build. It shouldn't be part of your code and was simply for reference.

1 Answer

Right, you should remove that section at the end or comment it out if you would like to leave it as a reference for what you want to make in the end.

You can also use Javascript Embedded Expressions to use your variable directly in a string like below:

/* Receive user input */
var noun = prompt("Input a noun:");
var adj = prompt("Input an adjective:");
var verb = prompt("Input a verb");

/* Alert the user that they are done */
alert('Input has been received. Your story is being crafted.');

/* Create sentence from the pieces. */
var story = `A young boy sold his ${adj} ${noun} to ${verb} a dog, but when he made it to the store they were all out.`; 
document.write(story);