previous

page 13

next
latest X in brown
new global
...
var g_last_x_el='';
do_x(id)
function do_x(id) {
if (g_last_x_el!='') {
g_last_x_el.style.color='blue';
}
var el=document.getElementById(id);
g_last_x_el=el;
el.textContent='X';
el.style.color='brown';
g_squares[id]=1;
}
another go

My plan is to just call setup() so we will have to make sure that everything is reset. Try to think what that entails before looking at mine.

setup()
function setup() {
for (var i=0;i<9;i++) {
var el=document.getElementById(i);
el.style.backgroundColor='linen';
el.style.color='blue';
el.textContent='';
g_squares[i]=0;
}
g_player=true;
g_message_el=document.getElementById('message');
g_message_el.textContent='the first to make XXX loses';
g_last_x_el='';
}
previous
next