previous

page 23

next

* is JavaScript for the multiplication sign.

my new one_row.js
function one_row(row) {
var s1=" <img src='counters/0.png' class='cell' id='";
var s2="' cn='0' onClick='cell_clicked(this);'>";
var id=row * 5;
for (var i=0; i<5; i++) {
document.write(s1 + id + s2);
id++;
}
var s1="<div id='s";
var s2="'>0</div>";
document.write(s1 + row + s2);
}

So when the player clicks a cell, cell_clicked can fetch the id like this:

var id=image.id;

It can then figure out the row number using the parseInt function which will return the integer part of the result of the division.

var row=parseInt(id/5);

It can then pass that row number to get_cns so it works on the clicked row.

var arr=get_cns(row);

And, finally, it can put the score in the right place thus:

var element=document.getElementById('s' + row);
element.textContent=score;
previous
next