I'm having a problem figuring out how to fix my code. I'm pretty new to Arduino and thought of a starter project of having a ultrasonic sensor beep before i get too close to something so i can walk around my house blindfolded.
Oh, 'distance' is a String! I didn't expect that because it's a very weird way to store integer values. I don't think the String class overload of '>' handles integers anyway, it's probably checking the string length.
I think you have just obscured everything with the library, you have no idea what is happening "under the hood". Please consult the library documentation and examples.
"Caution: String comparison operators can be confusing when you’re comparing numeric Strings, because the numbers are treated as Strings and not as numbers. If you need to compare numbers numerically, compare them as ints, floats, or longs, and not as Strings."
I didn't know exactly what '>' does in the String class because I never use the String class for anything. What it is, is a lexical comparison (in other words, a dictionary style ordering). Like,