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

Daniel DeBono
Daniel DeBono
3,067 Points

It Works! However i'm not sure if my presentation was right. Seems everyone has their own way of working it out.

I'd like some feedback on whether this is correct. The program works but I want to know if the 'way' I produced it is the 'right' way, I understand there are multiple ways this can be done, but I want to be sure that i'm doing it the correctly as well. JS Code is below;

var Adjective = prompt("Please provide a adjective."); var Noun = prompt("Please provide an noun.");

var FirstPart = "There once was a "; console.log(Adjective); var LastPart = " programmer, who wanted to use "; console.log(Noun);

alert("Your story has been completed, please select OK to view it.");

FirstPart += Adjective; LastPart += Noun + " to change the world."; FirstPart += LastPart;

var FinSentance = FirstPart;

document.write(FinSentance);

Much appreciated in advance!

1 Answer

Steven Parker
Steven Parker
231,269 Points

"Working" is easily 90% of "right" when it comes to programming. So good job on what you have already! :+1:

But there are a few "best practices" that are considered good to use, such as:

  • minimizing the use of variables
  • naming variables with "camel case" (beginning with a lower-case letter)

Applying those concepts might produce something like this:

var adjective = prompt("Please provide an adjective.");
var noun = prompt("Please provide a noun.");

console.log(adjective);
console.log(noun);

alert("Your story has been completed, please select OK to view it.");

var finSentence = "There once was a " + adjective + " programmer, who wanted to use " 
                  + noun + " to change the world.";

document.write(finSentence);