I am struggling to assign each cell a random double-digit number between 50 and 500. I have been attempting to use the Math.floor(Math.random()) function but have not had any success so far.
Additionally, I am trying to figure out how to target only one cell. For example, if I have a grid of 5x5 slots with 5 rows and 5 columns, how can I isolate the top left cell? Instead of a randomly generated number like the rest of the cells, I want to give it a specific symbol that I can control. That way, if the symbol is in the top left corner and I click on another cell, I can move the symbol there, replacing the generated number and leaving the top left corner empty.
I apologize for the inconvenience, any assistance would be greatly appreciated.
<html>
<head>
<style>
td{
border:2px solid black;
width:10px;
height:10px;
}
td:hover{background-color:lightgreen;}
.grn{
background-color:green;
color:white;
}
</style>
<body>
<div id='ff'></div>
<script>
var isCol=0;
var board=[];
for(r=0;r<7;r++){
var line=[];
for(c=0;c<7;c++){
line.push(r);
}
board.push(line);
}
function prs(c,r){
showTable(c,r);
isCol=(isCol+1)%2;
}
function toColor(col,row,chosen_col,chosen_row){
var ret=false;
switch(isCol){
case 0:
if(row==chosen_row){
ret=true;
}
break;
case 1:
if(col==chosen_col){
ret=true;
}
break;
}
return ret;
}
function showTable(chosen_col,chosen_row){
var str="";
str+="<table border=1>";
for(row=0;row<7;row++){
str+="<tr>";
for(col=0;col<7;col++){
str+="<td onclick='prs("+col+","+row+")'";
if(toColor(col,row,chosen_col,chosen_row)){
str+=" class='grn' ";
}
str+=">";
str+=board[row][col];
str+="</td>";
}
str+="</tr>";
}
str+="</table>";
document.getElementById("ff").innerHTML=str;
}
showTable(-1);
</script>
</body>
</html>