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
body
tag of the HTML file - Just like you can select page elements by
id
and byclass
, you can select elements bytagName
. And just like when you select byclass
, selecting bytagName
can mean you select more than one element, so you’ll get an array back (although in the case of thebody
tag, 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!