In an atom you have electrons whizzing around at particular energy levels. These energy levels are linked to what "shell" the electrons are in. The valence electrons (by definition) are in the furthest shell.
In the flame test, metals are heated and valence electrons temporarily gain energy. When they crash back down to a lower energy state the excess energy is released in the form of light.
With light, different frequencies correspond to different energy levels. Visually, our eyes interprer frequency as colour. For example, red light is lower frequency and energy than blue light.
The energy jump for electrons in a metal determines the frequency of light that is emitted. Some of these frequencies are within the visible spectrum & some are not. If the frequencies are in the visible spectrum we interpret that frequency as colour.
Hope this helps!
Edit: typos
To just add to this,
Emisstion spectra refers to all the different frequencies of light that atoms of a specific element can relsease when returning to lower energy levels. Some frequencies of light will be visable and some won't be.
All metals do have emission specta containing visable light, however not all metals produce characteristic flame colours. After a quick bit of reading it seems that this occurance is not fully understood, however the best guess is that for some metals (such as the noble metals including gold, silver, and platinum) the energy of the flame is insufficient to raise the atoms of that element to a higher energy state, thus it cannot emit its characteritic frequencies of light.
To summarise, not all metals produce a characteristic flame colour, but all metals can emit charactersitc frequencies of visable light (although metals can also produce non-visable light)
yeah, I'm just confused about how the CO2 and H2O will react with the CaCl2 or NaOH, otherwise, the question isn't too hard yes. Is there reason why co2 reacts with naoh and h2o reacts with cacl2?
(this is something I had to research)
CaCl2 readily absorbs water into its crystalline structure. Before the water vapour passes through the CaCl2, it is presumably anhydrous meaning doesn't have associated water molecules. As the water vapour passes through the CaCl2, it is absorbed by the compound and the compound becomes hydrated. We write this as: CaCl2 · nH2O (note that these absorbed water molecules aren't just floating around with the CaCl, they are part of its structure). Not all ionic compounds readily absorb water in this way to form hydrated compounds.
For the reaction of NaOH with CO2, there's really two different reactions occuring that can be combined to give the reaction:
NaOH + CO2 --> NaHCO3
These two reactions are:
the reaction of carbon dioxide with water to form carbonic acid:
CO2 + H2O --> H2CO3
and the reaction of the carbonic acid with the sodium hydroxide to form sodium bicarbonate and water:
H2CO3 + NaOH --> NaHCO3 + H2O
By combining these two seperate reactions and calcelling out the water apearing on both sides of the reaction, you get the overall equation mentioned earlier.
Hopefully this helps with understanding the reactions taking place - although I don't think you need to worry about memorising them as I think its a bit beyond VCE. That being said, knowing about hydrated compounds is helpfull as they do apear in the course (don't think you need to know specific examples of them though).