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

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
231,268 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.