My friend thinks he is smart
My friend thinks he is smart. He told me an onion is the only food that makes you cry, so I threw a coconut at his face.The humor in this joke is derived from the fact that the jokester misunderstood (either intentionally, or not, it isn't made obvious) the original statement made by the "friend" to mean "the only food that makes you cry under any circumstances" and not "the only food that makes you cry when you cut it".
The set-up makes it obvious that the "friend" is not actually a friend, but is in fact a person that the jokester is competing with to seem smart. The jokester's counterexample to the friend's statement (throwing a coconut at his face) is not really an example of being smart, but is instead an example of using brute force to solve a problem, so it really shows the jokester as an unintelligent person.
The end of the joke also makes the jokester seem to have an impulse control problem, which also contributes to the humor, because a person would not usually throw something at someone else's face.
Quasi-Science-Fact: you could also cry when cutting a citrus fruit (if it sprays in your eyes) or a hot pepper (if you are not careful about what you do with your hands).