Welcome to the Treehouse Community
Looking to learn something new?
Matthew Cahn6,301 Points
I didn't use the var identifier but it still works. Is there something wrong with programming like this?
Here's my code:
//Create a story-telling program: //1. Use the prompt() command several times to collect different types of words -- nouns, verbs, adjectives. //2. Store the result of each prompt() command in a different variable. noun1 = prompt("Enter a noun"); console.log(noun1); verb = prompt("Enter a verb"); console.log(verb); adjective = prompt("Enter an adjective"); console.log(adjective); noun2 = prompt("Enter a noun"); console.log(noun2); //3. Combine the variables with other strings to create one or more non-sensical statements. var statement = noun1 + ' ' + verb + " the " + noun2; //4. Print the resulting story to the browser using the document.write() command. document.write(statement); //Story: The noun1 verb the adjective noun2
David Trejo19,914 Points
Omitting the var keyword doesn't cause much of a problem in small programs. However, when you deal with larger scale programs it is best practice to use the "var" keyword to declare variable because omitting the "var" keyword in a variable causes the variable to become a global. Once a variable becomes global, its kind of available to all and modifiable from any source. I hope this helps -David