Which comparison to use?

I Just finished the Presidents Quiz app, getting spurious 'incorrect' when checking answer. the App Inventor book a 'text comparison' block; the App Inventor 2 book uses a math comparison? So I tried each, including the 'logical comparison' block, checking the texts to compare with 'label' blocks. Same results, seemingly random wrong answers when the texts were the same.
Turns out the reason for incorrect answers was that the autocomplete feature of my keyboard was adding a space at the end of my response! If I typed in the answer I got 'correct!' as expected, when I used autocomplete I was 'incorrect'.
My solution was to use a 'trim' block on my answer to remove the space. Works great now!
I've read the docs, the differences in the three compairers is still unclear to me. Any Ideas, experiences, clues?

welcome Alfred.

Yes, some cell phones place a space after the last letter 'typed' in a TextBox. The space must be removed if it exists before using a Compare Block on the value. :wink: You are using the correct solution. :slightly_smiling_face:

When you 'compare' with Math Blocks, you can only compare numerals.
When you 'compare' using the green Logic Blocks you can comapare numerals or alpha characters.

compare texts < > = ≠

Returns whether or not the first string is lexicographically <, >, =, or ≠ the second string depending on which dropdown is selected.

A string a considered lexicographically greater than another if it is alphabetically greater than the other string. Essentially, it would come after it in the dictionary. All uppercase letters are considered smaller or to occur before lowercase letters. cat would be > Cat.

trim

Removes any spaces leading or trailing the input string and returns the result.

contains

Returns true if piece appears in text; otherwise, returns false.

contains any

Returns true if any of the pieces in the piece list appear in text; otherwise, returns false.

This block can be obtained by changing the dropdown on the contains block.

contains all

Returns true if all of the pieces in the piece list appear in text; otherwise, returns false.

This block can be obtained by changing the dropdown on the contains block.

Thanks for clarifying SteveJG.
So it's the math block for numbers, the text block for text and the logic block for a mix of characters. Got it!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.