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
Casey Leonard
913 PointsVariable Story Challenge, please tell me where I went wrong!
Here is my story.js code; I am very, very new.
alert("Do you want to help create a story?"); var adj; adj = prompt("Give me an adjective");
var verb; verb =prompt("Give me a verb");
var noun; noun =prompt("Give me a noun");
var color; color =prompt("Give me a color");
alert("you are all done! enjoy the story."); document.write("Once upon a time there was a" + adj + "girl who met a unicorn who was" + verb "the unicorn gave the girl a" + noun "and the girl pooped a" + color "turd"); consule.log("The End");
2 Answers
andren
28,558 PointsYour code is actually not bad for a beginner, there are only a couple of small issues.
In your alert call you have forgotten to include the + operator after the verb, noun and color variables, which are necessary in order to concatenate them together with the string.
Also when you concatenate strings together no spaces are created, "Hello" + "World" for example would produce "HelloWorld". So to get proper spacing in your story you have to create a space manually at the start and end of your strings. You also have a typo in your last line, you have written consule instead of console.
Those are the only errors in your code. Though one other thing I'd mention is that when you create a variable and want to set it to a value right away, then it's cleaner to do that at the same time you create the variable. Instead of splitting it into two steps like you have done in your code.
Here is a revised version of your code with some comments added:
alert("Do you want to help create a story?");
// Assign a value to the variables as they are created.
var adj = prompt("Give me an adjective");
var verb = prompt("Give me a verb");
var noun = prompt("Give me a noun");
var color = prompt("Give me a color");
alert("you are all done! enjoy the story.");
// Added a + after the `verb`, `noun`, and `color` variables. And added spacing to the strings.
document.write("Once upon a time there was a " + adj + " girl who met a unicorn who was " + verb + " the unicorn gave the girl a " + noun + " and the girl pooped a " + color + " turd");
// consule changed to console.
console.log("The End");
Casey Leonard
913 PointsThank you! It's so rewarding to see I was on the right track and only a few errors were stopping me. Thanks for taking the time to answer.
andren
28,558 PointsNo problem. Most of the errors you made were essentially typos, which are quite easy to make in the beginning. The important thing is to understand the logic and structure of the language, and in that area your code was perfectly fine even before my corrections.
Good luck with your future coding .