The answer is Flourine i guessed and got it right!
For the compound formula, MgX₂, X must be a nonmetal element, because Mg is a metal, and when a metallic compound (bonds between metals) is represented we don't put the number of atoms.
The compound is ionic, so the partial charges of the elements are changed between them without the signal to form the compound. Magnesium has partial charge +2, so X must have partial charge -1, it means that it must be in the 7 groups of the periodic table, so it must be fluorine or iodine.
The density increase from the top to the bottom in the groups. Fluorine is in the 2nd period and iodine in the 5th period, so iodine has a higher density then fluorine.
Besides that, fluorine has a higher electronegativity, and because of that it is the most reactive element, and it is diatomic (F₂).
i think the answer is terrae but not 100 percent sure. ▓▬▬ §