Explain why ionic compounds are formed when a metal from the left side of the periodic table reacts with a nonmetal from the right side. Give two examples of such compounds.