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 JavaScript Basics (Retired) Storing and Tracking Information with Variables The Variable Challenge Solution

Different code, but same result.

My code was not the same as in the video. I am guessing that although this code works, it is probably not best practice? (ah I was so happy my program worked too, lol).

var adjective = prompt("Please type an adjective"); var verb = prompt("Please type a verb"); var noun = prompt("Please type a noun"); alert("You're all done!"); var story = "You were walking through the forest and saw " + adjective + " " + verb + " " + noun; document.write(story);

As long as it works it's fine.

Although I assume the solution shown is a bit more ease to read.

P.S. use triple backticks to make your code more readable in comments, like so.

var adjective = prompt("Please type an adjective");
var verb = prompt("Please type a verb");
var noun = prompt("Please type a noun");
alert("You're all done!"); 
var story = "You were walking through the forest and saw " + adjective + " " + verb + " " + noun;
document.write(story);

1 Answer

Steven Parker
Steven Parker
210,066 Points

In programming, there's rarely only one solution to any challenge. The more complex the task, the more ways there will be to solve it. Getting the correct result is at least 90% of a good solution.

The remaining 10% of "best practice" is ease of reading/maintaining, code compactness, and running efficiency. As you gain experience you will become able to evaluate those criteria as well.

But this short example seems to hit all the marks, good job! :+1:

Thank you so much! I really appreciate all of the tips!

Steven Parker
Steven Parker
210,066 Points

Chris Hendricks — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!