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

Need help understanding the usage of commas and quotation marks used here in the lesson

Here ------> "<h2>There once was a " + adjective; var verb = prompt('Please type a verb'); var noun = prompt('Please type a noun'); alert("All done. Ready for the message?"); sentence += ' programmer who wanted to use JavaScript to ' + verb; sentence += ' the ' + noun + ' <-----------Here document.write(sentence);

I understood you can interchange “ and ‘ (commas and quotation marks) as shown in the video lesson, right? Although to apply best practice you stay consistent, right? If so, I put quotation marks and it doesn’t run my code. What am I not getting about mixing commas and quotation marks used in the video versus me putting quotation marks at the end to be consistent?

1 Answer

Steven Parker
Steven Parker
216,865 Points

Commas ( , ) cannot be substituted for quotes ( " ), but apostrophes can ( ' :point_left: also known as a "single quote").

And the code shown above is missing part of the last literal string. There should be something (perhaps just a period) and another apostrophe, and ideally a semicolon all before the "document.write" statement:

sentence += ' the ' + noun + '       // incomplete, unbalanced 's
sentence += ' the ' + noun + '.';    // fixed

Thanks Steven for taking the time to respond and showing the results.