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

Kate Moore
Kate Moore
22,916 Points

Storymaker code does not write out my story

I'm recreating the storymaker test on my own. It runs through all of the prompts and alerts fine, but when it comes to accepting the alert, instead of writing out the sentence it leads to "This webpage is not found" what is wrong with my code?

var name = prompt('Give me your Alias');

var type = prompt ("Alright, " + name + " tell me, are you a male, female, or monster?");

var location = prompt ("Do you prefer your adventures in the lab or in the park?");

var activity = prompt ("Would you rather play with fire or eat candy?");

alert("Great! Thanks, I now have all the information I need. Are you ready to check out your adventure!?");

var sentence = "One day, " + name + " was having an adventure";

sentence += "in the " + location;

document.write(sentence);

2 Answers

A.J. Kandy
PLUS
A.J. Kandy
Courses Plus Student 12,422 Points

Ah, this is because location is actually a protected term in JavaScript, that refers to the URL. When you used it as your variable, you were actually asking for a URL, and when you inserted it in the concatenation string, the browser attempted to go to that URL.

https://developer.mozilla.org/en-US/docs/Web/API/Window/location

Try renaming your variable to place or `myLocation or something like that.

Kate Moore
Kate Moore
22,916 Points

That worked! I guess I need to be a little more creative :) thank you!

A.J. Kandy
A.J. Kandy
Courses Plus Student 12,422 Points

No worries! I wouldn't have seen that at first, either, but I saw the URL was going to the value I input for location, and that reminded me of the .location object...