explain how ions gain or lose electrons​