previous

page 27

next

So now we need a function to get the cn values from a column.
Call it get_col_cns(col) - it will be very similar to get_cns(row) so have a go yourself!

my get_col_cns.js
function get_col_cns(col) {
var arr=[];
var id=col;
for (var i=0; i<5; i++) {
var element=document.getElementById(id);
var cn=element.getAttribute('cn');
id=id + 5;
arr[i]=cn;
}
return arr;
}

Next we'll need to add to cell_clicked to make use of this new function.
A reminder that the % operator gives the remainder after a division.
For example, 17 % 5 = 2.

I added these lines just before the pick line in cell_clicked :

var col=id % 5;
var arr=get_col_cns(col);
var score=worth(arr);
var element=document.getElementById('s' + (col + 5));
element.textContent=score;
previous
next