Code:
<html>
<head>
<script language="javascript" >
<!--
var noCells=0;
var arrCells=new Array();
function fillCell(cellnum) {
//the function fills the cell selected by the human player
var txtDivLocation = "fc" + cellnum;
for(var i = 0; i < noCells; i++) {
if(i == cellnum) {
document.getElementById(txtDivLocation).style.background = "red";
} else {
var txtOtherDivLocation = "fc" + i;
document.getElementById(txtOtherDivLocation).style.background = "white";
}
}
}
function initialize() {
//creates an odd number btw 0 and 10
noCells=Math.floor(Math.random()* 10);
if ((noCells % 2)== 0)
noCells++;
//initializes the array of cells with 0 -empty cells
for (var i=0; i< noCells; i++)
arrCells[i]=0;
outputCells(noCells);
}
function outputCells(n) {
var txtNewText = "<html><head></head><body><p><center>THREE FILLED CELLS</center></p>";
txtNewText += "<table align = center cellpadding= \"0\" cellspacing=\"0\" border=\"3\" style='border-color:\"black\" ' ><tr>";
for (var i=0; i < n ; i++) {
txtNewText += "<td width= \"50\"><a href= \"javascript:fillCell("+i+");\" > <div style='border-color:\"black\";' id= \"fc"+i+"\" />***" + (i+1) + "***</a></td>";
}
txtNewText += "</tr></table></body></html>";
document.getElementById("dOne").innerHTML = txtNewText;
}
//-->
</script>
</head>
<body onload="initialize();">
<div id="dOne"></div>
</body>
</html>
Bookmarks