JavaScript JavaScript Basics (Retired) Storing and Tracking Information with Variables The Variable Challenge

Daniel DeBono
Daniel DeBono
2,910 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;


Much appreciated in advance!

1 Answer

Steven Parker
Steven Parker
203,226 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.");


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