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

Michele Kempinsky
Michele Kempinsky
12,201 Points

Is this a valid solution to the Variable Challenge?

For this challenge this is the code I came up with. Although it looks much different than the solution provided, when I ran the code it seemed to work perfectly. I'm just curious if this is improper form when writing JavaScript?

var Name = prompt('What is your name?'); var Color = prompt ('What is your favorite color?'); var Adjective1= prompt('Imput an adjective please.'); var Place= prompt('Name a place.'); var ClothingItem= prompt('Name a clothing item.'); var Adjective3= prompt('Imput another adjective please.'); var Adjective4= prompt('Ok, just one more adjective please.');

alert("Great! You're all finished! Now read your story!")

var my_story = "Hello, my name is " +Name +"! My favorite color is " +Color +". During the summer I like to take " +Adjective1 +" walks at the " +Place +". I wear my " +Color +" " +ClothingItem +" so that I don't get too " +Adjective3 +". Again, my name is " +Name +" and thanks for reading my " +Adjective4 +" story!" ;

document.write(my_story)

1 Answer

Steven Parker
Steven Parker
216,148 Points

It doesn't look so different to me. I see that you concatenated all your strings in one statement instead of doing it incrementally as the instructor did, but that yields exactly the same result.

Overall, I'd say that functionally your implementation is almost exactly the same as the instructor's. Good job! :+1: