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

My storymaker code isn't working...what am I doing wrong?

Hi everyone! :)

So excited about trying out my first official applied code. For the storymaker challenge, I tried using the concepts of concatenation and the prompt function in my code but for some reason, the prompt question isn't coming up.

Here's the code for it below:

var maincharacter = prompt ("Enter your name"); var mission = prompt ("Enter a verb"); var skill = prompt("Enter a different verb"); var place = ("Enter a place"); var story = "There once was a brave ninja named " + main character + " who dreamed about " + mission; story+= "One day, the brave ninja decided to go to " + place + "and upon arriving there, learned to " + verb + "instead. "; document.write(main character + mission + skill +place +story);

There's also a snapshot of it under "Story.js" https://w.trhou.se/e8943vbgbc

Thanks again for all your help! ^_^

4 Answers

Hi Ashley,

You have a little bit more wrong with your code than just spaces in your variables, but that's okay because we're here to help! You do have spaces in between "main" and "character" and that is a no-no in JavaScript. You have to remove the spaces so that the variable reads "maincharacter" in any reference to it. There are lots of characters you can use to give separation to words in a variable. A lot of times developers like to use camel case like this: mainCharacter.

Also, as Daniel Hildreth pointed out, "story.js" in the src of the script tag in "index.html" should be "Story.js".

You are also missing a prompt command outside of the parenthesis for place so that you can get some input on that haha

Also, in your line with "story +=" you are referencing a non-existing variable named verb which causes an error in execution. This should instead be skill.

The final thing is that you can just put the story variable into document.write() because otherwise, it comes out all funky! I also added some extra spacing so that some words are not bunched up! :D

var maincharacter = prompt("Enter your name");
var mission = prompt("Enter a verb");
var skill = prompt("Enter a different verb");
//added missing prompt before parenthesis
var place = prompt("Enter a place");
//added some spacing here to make the sentence not squished
var story = "There once was a brave ninja named " + maincharacter + " who dreamed about " + mission + ". ";
//changed verb to skill and added more spacing to avoid
//more squishing :P
story += "One day, the brave ninja decided to go to " + place + " and upon arriving there, learned to " + skill + " instead. ";
//all you need is story otherwise you get a jumble of random words haha
document.write(story);

Hi Marcus,

Thank you SO much for all the help! It really helped clarify many of the issues that I was having with my code and haha, thanks too for catching my silly mistakes and for the very helpful tips on organizing my code!! I really appreciate all the help. :D

You're very welcome, Ashley. If you want to go ahead and select a best answer, we can mark this as resolved! :) Happy Coding!

Look at your code. You have extra space in variable:

var maincharacter = prompt("Enter your name");
var mission = prompt("Enter a verb");
var skill = prompt("Enter a different verb");
var place = ("Enter a place");
var story = "There once was a brave ninja named " 
                  + main character // HERE IT IS
                  + " who dreamed about "
                  + mission;

story += "One day, the brave ninja decided to go to " + place + "and upon arriving there, learned to " + verb + "instead. ";
document.write(main character + mission + skill + place + story);

Thank you, wow, I didn't even notice that space when I was combining the strings! I shall be more careful next time! :)

Daniel Hildreth
Daniel Hildreth
16,170 Points

Also, in your index.html file you have it referencing a story.js file. You don't have a story.js file; you have a Story.js file.

Oooh, thanks Daniel! Now I know why my code wasn't working even after organizing my code. Wow, you guys are all great! My code is finally working now and I couldn't have done it without all your help.Thank you so much! :D