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 trialElfar Oliver
3,924 PointsI can't use the escape sequence for double quote or I just don't know where to input it. Maybe my return value is wrong
using System;
class Program
{
static string Quote(string phrase)
{
return Quote;
}
static void Main(string[] args)
{
// Quote by Maya Angelou.
Console.WriteLine(Quote("When you learn, teach. When you get, give."));
// Quote by Benjamin Franklin.
Console.WriteLine(Quote("No gains without pains."));
}
}
2 Answers
Steven Parker
231,269 PointsHere's a few hints:
-
Quote
is the name of the function, that's not what you need to return - the return value must be a string, and
phrase
will be part of it - you'll need to add a quote mark to the beginning and end of
phrase
- one of the ways to encode a quote mark is to escape it with backslash (example:
"say \"Yay!\""
)
Elfar Oliver
3,924 PointsI'll just give up and move on. Thanks though
Steven Parker
231,269 PointsIt might be worth working it out. β "No gains without pains." β
Elfar Oliver
3,924 PointsTried it for at least 30mins just inputting anything I could think of and I was nowhere closer
Steven Parker
231,269 PointsYou got the escapes now, but still:
- the surrounding quotes are imbalanced, you need one more at the beginning of the string
- as I said before,
Quote
is the name of the function, it won't be part of what you return -
phrase
will be part of what you do return - to put quotes around the phrase, you could use concatenation or interpolation (if they've covered that?)
Elfar Oliver
3,924 PointsYeah, I'm no closer than before. I tried " and \ all over the place and used phrase like you suggested and your hints are helping me just as much as the hints in the assignment. This is like PokΓ©mon, can't catch 'em all
Steven Parker
231,269 PointsYou're learning a new skill .. so there will hurdles to cross, but it's worth staying with them. Show me what you've got so far, I'll bet you're pretty close now.
Elfar Oliver
3,924 Pointsusing System;
class Program {
static string Quote(string phrase)
{
return ""\"phrase"\"";
}
static void Main(string[] args)
{
// Quote by Maya Angelou.
Console.WriteLine(Quote("When you learn, teach. When you get, give."));
// Quote by Benjamin Franklin.
Console.WriteLine(Quote("No gains without pains."));
}
}
Elfar Oliver
3,924 PointsI get where you're going with this hoping I'll get it and you'll get to "Attaboy" or whatever. But the problem with these assignments is they're unskippable and never supply the answer. If I'd have the answer I could compare that to what the objective is requesting instead of never getting it. It's so easy to understand the answer if you have it and learn from that
Steven Parker
231,269 PointsI was right, you were nearly there. You just had one quote out of place and were missing the concatenation operators (+
):
return "\"" + phrase + "\"";
Elfar Oliver
3,924 PointsI was never gonna get that because I don't even understand the placement of the ". They're not symmetrical and it's really confusing
return (")\"" + phrase + (")\"";
Are the " I put in brackets the actual quotes and the \"" are extra quotes? Making the return "\"" + phrase + "\""; a quote + quote + phrase + quote + quote?
Steven Parker
231,269 PointsThe "working" quotes (the ones defining strings) are symmetrical:
// vv vv these are the escaped "data" quotes
return "\"" + phrase + "\"";
// ^ ^ ^ ^ these are the "working" quotes (one pair for each string)
Benjamin Deollos
2,097 PointsSteven Parker thank you for your explanation on this. I was getting hun up on doing it all in the method or adding the separators to the literal in console.writeline()
Elfar Oliver
3,924 PointsElfar Oliver
3,924 Pointsusing System;
class Program {
Any closer with that?