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

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...