previous

page 11

next
the win/lose messages

To save repeatedly looking up the message element, I decided to do it just once and store it in a global g_message_el. The catch is I won't be able to do this till after the message div is loaded so this would be a good time to shift setup() to the end of my index.html.

index.html
...
<div id='grid'>
<script>squares();</script>
</div>
...
</div>
<script>setup();</script>
</body>
</html>
globals.js
var g_squares=[];
var g_result;
var g_player;
var g_message_el;
setup()
function setup() {
for (var i=0;i<9;i++) g_squares[i]=0;
g_player=true;
g_message_el=document.getElementById('message');
}
previous
next