"The girl has a book."
Translation:La fille a un livre.
It's mostly an 'it sounds right' system that's instinctual for natives like when to use "a" or "an" in English. Here are the "patterns" in flashcard format: https://tinycards.duolingo.com/decks/bfNY8E/french-gender-hacker
As georgeoftruth wrote, you have to learn the gender of the word when you learn the meaning. The easiest way to do this is to memorize the indefinite article along with the word. Une pomme, un vélo, une voiture, etc. However, while not 100% guaranteed, certain noun endings may give you a clue. Here's a useful post.
The article corresponds with the noun being used. "Fille" is a feminine noun so the girl is "la fille." "Livre" is a masculine noun, a book is "un livre."
If it helps, just think that all nouns fit into two categories. Feminine and masculine are convenient labels, but it doesn't have anything to do with the nature of the object being feminine or masculine. There is nothing particularly feminine about une table, a table, that is just the category it belongs to. Logic won't help you determine the category (outside of the obvious female people are feminine and male people are masculine). They could be called X and Y rather than feminine and masculine. The point is you will need to memorize the article that belongs to the noun whenever you learn a new word. This will save you a lot of trouble down the road as your vocabulary grows.