look at the periodic table and see what group the elements are in.
H is in Group IA and O is in Group VIA. That means 1 and 6 valance electrons respectively. You will notice that O has 8 total electrons because it's the 8th element. The first two are in the K shell in the s sub orbital. Any of this ringing a bell? Oxygen, 1s2 2s2 2p4 is another way of doing it. In each term, the first number is the shell, the letter is the sub-orbital, and the second number is the number of electrons. So the number of electrons in the valence shell (the outermost shell 2) is 6 for Oxygen