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 trial

iOS

Vidit Shah
Vidit Shah
6,037 Points

NSString Task

NSString *color=@"Purple"; NSString *preference=@"My favorite color is"; NSString *favorite=[color stringByAppendingString:preference]; NSLog(@" %@",favorite);

//Its perfectly working in Xcode.But not in The environment provided by Treehouse.

I tried your code in Xcode

  NSString * color = @"Purple";

  NSString * preference = @"My favorite color is";

  NSString * favorite = [color stringByAppendingString:preference];

  NSLog(@" %@",favorite);

The result is

 PurpleMy favorite color is

If you change favorite to this

  NSString * favorite = [preference stringByAppendingString:color];

You got

My favorite color isPurple

Add a space to preference

  NSString * preference = @"My favorite color is ";

5 Answers

NSString * favorite = [NSString stringWithFormat: "%@ %@", preference, color];

Vidit Shah
Vidit Shah
6,037 Points

Task is asking me to use method :StringByAppending String

use NSMutableString instead of NSString

NSMutableString * color = @"Purple";

Vidit Shah
Vidit Shah
6,037 Points

But thats not yet taught..!

Vidit Shah
Vidit Shah
6,037 Points

BRO everything is working fine is Xcode but in the compiler provided by them it states, Bummer! Make sure to assign the correct value to 'favorite'.

I think the correct answer should be

My favorite color is Purple

But in your code shows

 PurpleMy favorite color is

as the answer

Vidit Shah
Vidit Shah
6,037 Points

Ya that was correct :P.

You are welcome, Please mark my answer as correct, so I can get the points :D