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 trialHaldon Francis
619 Pointsusing System; class Program { // YOUR CODE HERE: Define a Quote method! static string Quote(string phrase) {
I would like to see the solution to this Challenge, please?
using System;
class Program
{
// YOUR CODE HERE: Define a Quote method!
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.\""));
}
}
4 Answers
Haldon Francis
619 PointsThank you, this helped. The video I watched on the topic did not explain concatenation like this. I'm also a beginner so an example for me would be much clearer than worked. but thanks much for your patience.
Steven Parker
231,198 PointsYou're already close, the method declaration including types, access, parameter, are all good.
Now instead of returning the parameter is it is, use concatenation (+) to add a quote character before and after it.
But do all your work in the new function, do not modify the provided code in the Main section. The challenge will call your function directly to test it with different data.
Steven Parker
231,198 PointsTo represent a regular quote, you'd need to put it inside single quotes, like this '"'
Then, you'd need to concatenate one of those both before and after the phrase (making a "sandwich").
Haldon Francis
619 PointsI am not quite sure I understand.
****return (phrase " " + " ")
Do you actually mean like this?
Haldon Francis
619 PointsCan you please leave an example. This would help much more speedily than an explanation.
Ex. return (“ “ + phrase + “ “)
Steven Parker
231,198 PointsYou've nearly got it there, except you're adding spaces (" "
) and you need quote marks ('"'
).
Steven Parker
231,198 PointsSteven Parker
231,198 PointsHaldon Francis — Did you mean to mark your own comment as "best answer"?
(You can still change it)