Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

Tristan-Olivier Boily
Tristan-Olivier Boily
3,445 Points

Signing 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
David Collins
6,643 Points

Drop the square brackets from the condition in the if statement. if ( isCorrect == YES )

Tristan-Olivier Boily
Tristan-Olivier Boily
3,445 Points

I 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!

oscar gonzalez
oscar gonzalez
7,072 Points

This 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
oscar gonzalez
7,072 Points

This 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]; } :)

this helped a lot i was using the square brackets instead of ( ) thank you!

David Collins
David Collins
6,643 Points

There 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
Tristan-Olivier Boily
3,445 Points

Well, 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
David Collins
6,643 Points

You're almost there, you don't need the square brackets as your not calling a method.

Tristan-Olivier Boily
Tristan-Olivier Boily
3,445 Points

Thank 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
Tristan-Olivier Boily
3,445 Points

So 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
David Collins
6,643 Points

Remember 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
Tristan-Olivier Boily
3,445 Points

You saved my life! I was missing the .self!