There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
So what does it mean when it’s asking me too Interpolate? Interpolate is used in the Console.WriteLine function and I’m not supposed to use that until step 2. I thought.
Strings can be printed to the console with the Console.WriteLine() method, but that isn’t the only thing we can do with them. Strings can be stored as values assigned to variables. A string value constructed with interpolation is still a string, and can be assigned to a variable as the instructions ask:
For example, if I were going to assign a string to a variable named message using values stored in other variables, I could do this:
string greeting = "Hello";
string name = "Karen";
int cookiesEaten = 7;
//use string interpolation
string message = $"{greeting}, {name}. Today I ate {cookiesEaten} cookies.";
//print message
Console.WriteLine(message);
I think there needs to be a clearer example of what is being asked for in this section, the right answer requires an additional step that is not given in the example itself.
I have been using this site for months now and I am running into a pattern with the lessons. They start off VERY STRONG, but a few lessons in, I notice that the developers get VERY lazy when it comes to questions in the lesson. In this one SPECIFICALLY, doesn’t clearly tell the student that they want you to include your own “beginning” “middle” and “end” string for 2 lessons.
So, even though we may have been on the right track, that wasn’t after we hit the View Solution button. I hate pressing that button, because it shows that I am not willing to investigate it more. But this is different, I am pressing the View Solution button when I know that I am right, but your instructions are unclear.
It’s very hard to suggest this to others and friends when I know that this is the EXACT issue they will run into with.
Sorry about the post, but I am very passionate about teaching people and I am not for miscommunications on the developers side.
I’m very stuck on this question. It’s confusing. So, I’m declaring the story string but also interpolating the variables? But there’s no additional linking text between the variables? so am I using the already quoted story text?
Nothing I do seems to work.
Please can I get some actual guidance?
I agree with what the others are saying in this thread. This exercise is lacking proper information on different use cases of interpolation.
Based on the lesson, interpolation is done on the Console.WriteLine() command. There’s no mention that interpolation can be done on different commands.
The lesson should provide multiple different instances where interpolation can be used.
If these lessons are meant for people who have little to no experience with coding, then they need to be a bit more heavy handed.
Also, the whole exercise could of been done by just doing interpolation with Console.WriteLine(), rather than creating a whole separate string variable. The only thing stopping you is the requirements of the exercise itself.
I have an issue understanding why string interpolation is easier to write than string concatenation.
It took me way longer to write the code:
string story=$"{beginning}{middle}{end};
than simply writing it like this->
string story=beginning+middle+end;
I don’t understand the logic very much. Can someone help me? Did i even write the code right?
I think this example doesn’t really show when interpolation would be useful. For writing stories, it’s probably not that great. However, for text where a variable might change, it’s really useful.
For example, let’s say you make a video game where Deb has to collect 5 apples. We start with an int called appleCount, which increases by 1 every time Deb finds an apple. There’s a button you can press to find out how many apples Deb has found.
Without string concatenation, one solution might be to have six lines of code that are dependent on different appleCount values - so if Deb has 0 apples, it would print “Deb has 0 apples!”; if Deb has 1 apple it would print “Deb has 1 apples!” and so on.
This isn’t very efficient code. Instead you could use string concatenation to do something like the following:
string apple = "Deb has {appleCount} apples!"
This is also the case for other use cases - a money tracker might have an interpolated string like "This month you have spent {outgoings} and saved {savings}!" or a location app might have something like "You have checked into this location {visitNumber} times!"
It’s weird that they chose writing a story as the format for teaching this, but I hope my explanation made the logic/reasoning for interpolation clearer!
this excercise is dumb. the theory teaches to interpolate when writing to the console it doesn’t mention anything about interpolating to a new string variable. like come on make it clearer, this is what turns people off
// Declare the variables
string beginning = "Once upon a time,";
string middle = "The kid climbed a tree";
string end = "Everyone lived happily ever after.";
// Interpolate the string and the variables
string story = $" {beginning} {middle} {end}";
// Print the story to the console
Console.WriteLine(story);
If anyone is confused written above is what your looking to write.
The tutorial was no help figuring out what it wanted you to do.
P.S. Your welcome…
ye iv done same what i dont get is my code was
string story = $“ok so {beginning } timmy the kid {middle} {end} the end”;
now why dont it work just because i put some text before the veriable