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 trialTony McCabe
8,445 PointsStrings
var statement1 ="She said\ "How's the family";
Im a little confused??????
14 Answers
Armando Amador
6,813 PointsCode Challenge: In 'strings.js' file define a string called 'statement' with the text of - She said "How's the family?"
The reason it keeps telling you 'Variable is not defined' is because you used 'statement1' as your variable. The variable you should use is 'statement'
var statement = 'She said "How\'s the family?"'
Hope that helps Tony
Armando Amador
6,813 PointsHey Tony, I think this is what you're looking for
var statement1 = 'She said, "How\'s the family"';
Tony McCabe
8,445 PointsFinally Got it!! Thanks Armondo..
Graham Davidson
Courses Plus Student 14,966 PointsWhy are you confused Tony?
Marcus Tisäter
4,886 PointsHmmm.... When you want to input ' into the sentence you have to input \, also you can't use "" in a "" string quote. Single quotes are recommended using instead. Look at this example:
var statementTony = 'He said "This is Tony\'s"';
Now try this with you're variable :)
Good luck
Tony McCabe
8,445 Pointsvar statement1 = "She said, How's the family"; it continues to say variable not defined {
var statementTony = "She said, How\s the family";
Tony McCabe
8,445 PointsStill can't seem to get through?
Scott Magdalein
2,406 PointsTry: var statement1 = "She said, \"How's the family?\"";
Since you're using double quotes ("
) for the string, the single quotes don't need to be escaped with a \
. You do, however, need to escape the double quotes so that they aren't misconstrued as the end of the string declaration.
If you're setting this in the console (e.g. in Chrome Dev Tools), you'll get immediate feedback of undefined
, but then if you call statement1
in the console, it'll show you the value has been set properly to "She said, "How's the family?""
. The extra double quotes on the front and back indicate that it's a string and not another value. To prove this, run typeof(statement1)
in the console after you've declared the variable and you should get "string"
.
Hope that helps.
Tony McCabe
8,445 Pointsvar statement = "She said, How's the family?\""; and var statement1 = "She said, \"How's the family?\""; tried both of these and more I'm not sure whats wrong!!?
Scott Magdalein
2,406 PointsMaybe it'll help to know what you're trying to accomplish.
Armando Amador
6,813 PointsYou can use either one.
var statement1 = 'She said, "How\'s the family"';
var statement2 = "She said, \"How\'s the family\"";
Tony McCabe
8,445 PointsSorry Armondo still don't work for eaither one. It say's you haven't defined the "statement" variable
Armando Amador
6,813 PointsI was confused by you're question. If you're trying to pass the code challenge the correct 'statement' is
var statement = 'She said "How\'s the family?"'
But since you wrote var statement 1 i thought you just wanted clarification.
Omh MG
19,233 PointsHaving the same issue here, however it's telling me "Bummer! You've the string is the incorrect value remember to use \ before the " or '."....
My code for this challenge is var statement = 'She said, "How\'s the family"';
Help, anyone? This should be working
Omh MG
19,233 PointsIt's working now.
Vincenzo Lanza
6,185 PointsIn my case this code is not correct, why? var statement = 'She said, "How\'s the family"';