
previous

page 5
next
Modify your program so this what it produces:
Let's think about how we can work out the score for this row.
We're going to need to know the counter number that is in each cell.
I imagine ending up with an array like this [6,0,6,4,6] which we can then send to a function to evaluate it.
So we need to add a new attribute to each cell that stores the counter number. Let's call it cn.
<img src='counters/6.png' class='cell' cn='6'>
So in our JavaScript we can use getAttribute to get each cn value.
Or can we?
How can we refer to each cell?
Each cell needs a unique identity.
Fortunately, html offers the id attribute.
<img src='counters/6.png' class='cell' id='0' cn='6'>
<img src='counters/0.png' class='cell' id='1' cn='0'>
<img src='counters/6.png' class='cell' id='2' cn='6'>
<img src='counters/4.png' class='cell' id='3' cn='4'>
<img src='counters/6.png' class='cell' id='4' cn='6'>
<img src='counters/0.png' class='cell' id='1' cn='0'>
<img src='counters/6.png' class='cell' id='2' cn='6'>
<img src='counters/4.png' class='cell' id='3' cn='4'>
<img src='counters/6.png' class='cell' id='4' cn='6'>
previous
next