Explanation: Atoms gain or lose electrons to get a full outermost energy level.
Atoms want to be happy and they can achieve that by the octet rule. It states that 2 atoms can go in the first shell and after that 8 can go in the second shell and so on. Atoms want to have a full outer shell of 8 electrons unless their the elements with fewer protons like hydrogen and helium since they will need 2 electrons to satisfy the octet rule.