previous

page 21

next

While we're testing, change the 9 to a 2 so we're more likely to get some of the higher value rows.
Next we have to use this pick variable in the cell_clicked function.

function cell_clicked(image) {
image.src='counters/' + pick + '.png';
image.setAttribute('cn',pick);
var arr=get_cns();
var score=worth(arr);
var element=document.getElementById('s0');
element.textContent=score;
}

Give it a try and see if you can figure out why the counters are all the same each time. How can we fix this?

What is needed is to do another pick after we've dealt with each click. So this line has to be added to the cell_clicked function.

pick=Random(2);

When you've checked that all the possible rows are scored correctly, you can change the 2 back to a 9.

Notice that at the moment you can click on a counter to change it. You may like to think how to stop that but for now it is handy for testing.

So it's time to try our work with 2 rows.
Simple duplicate this code in index.html.
Have a good play and see if you can figure out what the problem is.

<div class='row'>
<script>one_row();</script>
</div>
previous
next