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 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
231,271 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: