Li+ + F = LiF
The lithium ion is 1+ (because it's in group 1, needs to get rid of one electron, making it one electron shorter, electrons are negatively charged), and the fluoride ion is 1- (because it's in group 7 and it needs one electron, gaining one negatively charged electron), so they balance.
2 K+ + O2- = K2O
The potassium ion is 1+, and the oxygen ion is 2-, so you need two K+ ions to balance the O2- ion. (Basically, oxygen needs two electrons for a full outer shell because it's in group 6, potassium only needs to get rid of one electron because it's in group 1, therefore you need two potassiums so that they can give oxygen the 2 electrons)
Mg2+ + 2 Cl - = MgCl2
The magnesium ion is 2+, and the chloride ion is 1-, so you need two Cl- ions to balance the Mg2+ ion. (Basically, the magnesium needs to get rid of 2 electrons to have a stable outer shell, chloride only needs one electron, so you need two chlorides so that magnesium will be happy.)