Due: Tuesday, Sep. 29th by 8:00pm
function processClick(tileId){}
. This will create a variable called tileId that you can use anywhere inside the function (within the curly braces), but not outside of it.
<td>
tag and since we are waiting for a click, we need to insert an onClick
handler to each of those cells. In generic terms, this will look like this (You must change this code to fit your needs; Just copying and pasting this example will not do you any good) : <td id="myCell" onClick="myfunction(this.id);">
The this.id
part forwards the id of the cell to the called function so it can properly process the click. By the way,
this
always refers to the object you are currently dealing with, so in this case the applicable <td>
.
document
and everything in the page lives under the document
object. We can use document.getElementById(desiredId)
to get any item (technically speaking any "object") from the page. You already know the id of the clicked tile as it was passed to the function from the event handler. So you could use document.getElementById(tileId)
. This will give you the <td>
object for the clicked tile. This tile itself has a property (which is sort of like a variable) called innerHTML. So document.getElementById(tileId).innerHTML
will get you the number that is in the currently clicked cell.
innerHTML
, like so:document.getElementById(tileId).innerHTML="I love my cat";
You can do this in many ways. However, to make it a little easier for you, we have defined a global variable called clickedcell
that initially holds an empty string. You may use this variable to remember what tile the player has clicked (do not use var
to recreate it). Obviously you need to also empty it out after each swap.
<td>
has things such as innerHTML
and also one called style
. This lets you change just about everything about how the object looks, including its style.backgroundColor
which you can read and write the exact same way as innerHTML
.
Oh, one more thing, colors are defined in hexadecimal RGB space. So orange is #D35400
and white is #FFFFFF
. Play around with it a little and see what cool colors you can come up with.
alert
message.