Challenge: Fill the Web Page with the Winning Colour
Your game works now, so here’s a challenge for you: using your new coding knowledge, can you fill the web page with the winning colour when the player clicks the correct button?
You need to know two other things to meet this challenge:
- The whole of the web page is contained in the
bodytag of the HTML file - Just like you can select page elements by
idand byclass, you can select elements bytagName. And just like when you select byclass, selecting bytagNamecan mean you select more than one element, so you’ll get an array back (although in the case of thebodytag, there will only ever be one element with thattagName).
Now try to use document.getElementsByTagName() to change the background of the page to the winning colour when the player clicks the correct button!