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 trialTristan-Olivier Boily
3,445 PointsSigning Up New Users Part 1 Code Challenge
I am having difficulty with the third part of the challenge. The question is: "If the guess is correct, we want to alert the user with a message using a UIAlertView. Add an if statement that checks if the BOOL variable 'isCorrect' is true (or 'YES'). Inside the if statement, declare a new UIAlertView variable named 'alertView'. Alloc/init it with the method 'initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles'. For the title, use "Hooray!", for the message, use "You did it!", for the delegate use nil, for cancelButtonTitle use "OK", and for otherButtonTitles use nil."
I used:
if ([isCorrect == YES]){ UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Hooray!" message:@"You did it!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; }
What is wrong with my code?
5 Answers
David Collins
6,643 PointsDrop the square brackets from the condition in the if statement. if ( isCorrect == YES )
oscar gonzalez
7,072 PointsThis was my answer and it worked for me !
// Check to see if the user's number is correct BOOL isCorrect = [GuessEngine testGuess:userNumber]; if(isCorrect==true || isCorrect==YES){ UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Hooray!" message:@"You did it!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; } :)
oscar gonzalez
7,072 PointsThis was my answer and it worked for me !
// Check to see if the user's number is correct BOOL isCorrect = [GuessEngine testGuess:userNumber]; if(isCorrect==true || isCorrect==YES){ UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Hooray!" message:@"You did it!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; } :)
Christian Deciga
5,600 Pointsthis helped a lot i was using the square brackets instead of ( ) thank you!
David Collins
6,643 PointsThere are 2 things you need to look at. The last sentence in the question shows that the properties are provided for you, assume that they are declared in the header file. Square brackets are used when you call methods.
Tristan-Olivier Boily
3,445 PointsWell, based on what you said, I tried [self.username = self.usernameField.text]; [self.password = self.passwordField.text];
but I defenitly can't get it right!
David Collins
6,643 PointsYou're almost there, you don't need the square brackets as your not calling a method.
Tristan-Olivier Boily
3,445 PointsThank you so much! I got it! Now I will try doing the second task. It's not working for now but I'll work my way through it!
Tristan-Olivier Boily
3,445 PointsSo David, thanks again for your help. Maybe you could help me more? I am having difficulties with that code challenge! In the second part, the task is: Next, create a new PFUser variable named 'newUser' and initialize it using the 'user' class method from PFUser. Set the 'username' and 'password' properties of this user using the properties you just set.
And I tried, like seen in the video:
PFUser *newUser = [PFUser user];
newUser.username = username;
newUser.password = password;
But it isn't working. That code challenge is definitly really hard for me! It's the first one I spend so much time!
David Collins
6,643 PointsRemember that your setting the newUser.username property to a property that has been already been declared.
self.username = self.usernameField.text;
Sorry if it's a bit vague, but I think it's best if you can figure out where you're going wrong. That hint should help.
Tristan-Olivier Boily
3,445 PointsYou saved my life! I was missing the .self!
Tristan-Olivier Boily
3,445 PointsTristan-Olivier Boily
3,445 PointsI actually finally found it out by myself! Now I'm stuck in the Part 2... (Question: In our view controller below we want to sign up new users for our app. In the signup method, start by capturing the username and password from two UITextField properties: 'usernameField' and 'passwordField'. Store the values in the properties 'username' and 'password'.) And i'm using:
NSString *username = [self.usernameField.text]; NSString *password = [self.passwordField.text];
Thanks for your help David!