NewOnThis
10-31-2005, 06:52 PM
I'm trying to make a game.I create an odd random number of cells and if a click on one cells it must change color. My problem is that the function fillCell called in the tag <a> is not seen by the browser. It doesn't do anything and I can't see why.
Tks
Here is the 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
}
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){
document.writeln("<center>THREE FILLED CELLS</center><br />");
document.writeln("<table align = center cellpadding= \"0\" cellspacing=\"0\" border=\"3\" style='border-color:\"black\" ' ><tr>");
for (var i=0; i < n ; i++){
document.writeln("<td width= \"50\"> <a href= \"javascript:fillCell("+i+");\" > <img src= \"color.gif\" border= \"3\" style='border-color:\"black\"' name= \"fc"+i+"\" /> </a></td>");
}
document.writeln("</tr></table>");
}
//-->
</script>
</head>
<body onload="initialize()">
</body>
</html>
Tks
Here is the 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
}
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){
document.writeln("<center>THREE FILLED CELLS</center><br />");
document.writeln("<table align = center cellpadding= \"0\" cellspacing=\"0\" border=\"3\" style='border-color:\"black\" ' ><tr>");
for (var i=0; i < n ; i++){
document.writeln("<td width= \"50\"> <a href= \"javascript:fillCell("+i+");\" > <img src= \"color.gif\" border= \"3\" style='border-color:\"black\"' name= \"fc"+i+"\" /> </a></td>");
}
document.writeln("</tr></table>");
}
//-->
</script>
</head>
<body onload="initialize()">
</body>
</html>