Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making the app recognize "the right answer"

I am new in the game, so probably an easy issue. What I am trying to do is to make an app with a question asked, and a textFiled in which to answer. Then, i want the app to recognize when the answer is right (in this case the number 25) and when it is wrong (not 25). Everything is working fine, and I get the "wrong" message, but I cant make it recognize the right answer.

- (IBAction)btnSubmitAction:(id)sender {
if (textFieldAnswer.text == @"25") {
    lblAnswer.text = @"Yes, your right!";
    btnNext.hidden = 0;
} else {
    lblAnswer.text = @"No, try again.";
}

}

Thanks a lot!

like image 747
mort Avatar asked Sep 15 '26 01:09

mort


1 Answers

Well, this is how you're supposed to compare strings:

- (IBAction)btnSubmitAction:(id)sender {
if ([textFieldAnswer.text isEqualToString:@"25"]) {
    lblAnswer.text = @"Yes, you're right!";
    btnNext.hidden = NO;
} else {
    lblAnswer.text = @"No, try again.";
}
}
like image 140
Alladinian Avatar answered Sep 17 '26 13:09

Alladinian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!