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 trialTayZar Soe
1,695 PointsI don't quite understand the quotation marks here.
var questionsLeft = ' [ ' + questions + ' questions left]';
Above is the placement of the quotation marks according to the instructor. I get that strings are meant to be left inside quotes and numbers don't have any quotes. What's the purpose of the single quotation mark immediately after opening bracket. Why don't we need closing quotation mark after left since it's supposed to be a string.
4 Answers
Ricardo Hill-Henry
38,442 Points"Questions" is a variable, I assume that holds a numerical value. That variable is being concatenated with two strings. A string starts with a quotation, and ends at the next quotation; which is where you're being confused here. The opening bracket is a string of its own, it's concatenated with whatever value "questions" holds, which is then concatenated with the second string, ' questions left]'. After concatenation, questions will no longer be an expression, but rather one long string value.
var questions = 5,
questionsLeft = '[' + questions + ' questions left]';
console.log(questionsLeft); //this would return the string "[5 questions left]"
It may be more intuitive seeing it with string interpolation
var questions = 5,
questionsLeft = `[${questions} questions left]`;
console.log(questionsLeft); //this would return the string "[5 questions left]" as well
Another way to look at it could be to imagine the types
//Note: not actual code to be ran, just an example
var questions = Number,
questionsLeft = String + Number + String;
console.log(questionsLeft); //returns String
someguy1234
3,450 PointsOh I got it now. Same here that I didn't recognize that a bracket [ is a string. Thanks!
Honza Noel
2,779 PointsI get it now!! Love that I'm not the only one confused! Was just about to pack it all in. Thanks.
Lia Seltene
2,641 PointsChrist thank you ;_; You, Mace, and andren, saved my butt here.
TayZar Soe
1,695 PointsTayZar Soe
1,695 PointsThat helped out a lot. I failed to realize that the brackets are meant to be a string; hence, the opening bracket was inside quotation marks. Thank you for your help. Cheers.
Dylan Jasper
1,847 PointsDylan Jasper
1,847 PointsAwesome thanks!
bill curry
Front End Web Development Techdegree Student 7,841 Pointsbill curry
Front End Web Development Techdegree Student 7,841 PointsVery helpful. Thanks Ricardo.
The brackets threw me off too.
Lynnette Acton
6,867 PointsLynnette Acton
6,867 Pointsthank you Ricardo!!
Rebekah McCarley
1,835 PointsRebekah McCarley
1,835 PointsTHANK YOU. That was really throwing me off as well.