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!
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
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