How can you tell if an element wants to gain or lose electrons?
Metals lose electrons, nonmetals gain electrons
In general, metals will lose electrons to become a positive cation and nonmetals will gain electrons to become a negative anion. Hydrogen is an exception, as it will usually lose its electron. Metalloids and some metals can be can lose or gain electrons.
This is not always true, as elements such as nitrogen can lose electrons to become positive. When an ionic compound forms, the more electronegative element will gain electrons and the less electronegative element will lose electrons.