Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript&;HTML-令牌未出现在connect four board上_Javascript_Html_Css_Arrays_Function - Fatal编程技术网

Javascript&;HTML-令牌未出现在connect four board上

Javascript&;HTML-令牌未出现在connect four board上,javascript,html,css,arrays,function,Javascript,Html,Css,Arrays,Function,我正在使用javascript、html和css创建一个connect-four游戏,我在game.js中的refreshGrid()函数遇到了问题。运行我的html文件目前只是一块空白的电路板,这个函数的作用是当用户点击电路板上的空白区域时,就会出现一块芯片。我不知道为什么这个函数不起作用,希望能得到一些帮助。我不确定我是否正确地遍历了我的行和列 var-player=1; 变量网格=[ [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0,

我正在使用javascript、html和css创建一个connect-four游戏,我在game.js中的refreshGrid()函数遇到了问题。运行我的html文件目前只是一块空白的电路板,这个函数的作用是当用户点击电路板上的空白区域时,就会出现一块芯片。我不知道为什么这个函数不起作用,希望能得到一些帮助。我不确定我是否正确地遍历了我的行和列

var-player=1;
变量网格=[
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0]
];
函数选择列(col){
如果(玩家==1){
网格[5][col]=1;
玩家=2;
document.getElementById(“box1”).innerHTML=“玩家1的回合”;
}否则{
网格[5][col]=2;
玩家=1;
document.getElementById(“box1”).innerHTML=“玩家2的回合”;
}
刷新网格();
}
函数refreshGrid(){
对于(变量行=0;行<6;行++){
对于(变量col=0;col<7;col++){
如果(网格[行][col]==0){
document.getElementById(“单元格”+行+列).style.backgroundColor=“#FFFFFF”;
}else如果(网格[行][col]==1){//1表示黄色
document.getElementById(“单元格”+行+列).style.backgroundColor=“#ffffff00”;
}else如果(网格[行][col]==2){//1表示黄色
document.getElementById(“单元格”+行+列).style.backgroundColor=“#FF0000”;
}
}
}  
}
轮到玩家2了。

您的代码中有太多错误。我甚至不知道从哪里开始,我会用我记得的东西和提示来编辑这篇文章

var-player=1;
变量网格=[
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0]
];
函数选择列(col){
for(设行=0;行<7;++行){
if(网格[行][6列]){
继续;
}
如果(玩家==1){
网格[行][6列]=1;
玩家=2;
document.getElementById(“box1”).innerHTML=“玩家1的回合”;
}否则{
网格[行][6列]=2;
玩家=1;
document.getElementById(“box1”).innerHTML=“玩家2的回合”;
}
打破
}
刷新网格();
}
函数refreshGrid(){
对于(变量行=0;行<6;行++){
对于(变量col=0;col<7;col++){
const htmlElement=document.querySelector(`column-${6-col}.row-${row}`);
如果(网格[行][col]==0){
htmlElement.style.backgroundColor=“#FFFFFF”;
}else如果(网格[行][col]==1){//1表示黄色
htmlElement.style.backgroundColor=“#FFFF00”;
}else如果(网格[行][col]==2){//1表示黄色
htmlElement.style.backgroundColor=“#FF0000”;
}
}
}  
}
.column{
显示:网格;
网格自动流:行;
}
#网格{
显示:网格;
网格自动流:列;
}
轮到玩家2了。

控制台中的
ReferenceError
应该是一个好的开始。