Javascript “迷你”;记分员“;项目-有一些问题

Javascript “迷你”;记分员“;项目-有一些问题,javascript,project,Javascript,Project,我正在开发一个简单的记分员应用程序,但有一些东西并没有达到预期的效果 以下是我的部分代码: if ( p1ScoreCount === inputScore.value) { p1Span.classList.add("green"); gameOver = true; alert("Player 1 Wins!"); } else if ( p2ScoreCount === inputScore.value) { p2Span.classList.add(

我正在开发一个简单的记分员应用程序,但有一些东西并没有达到预期的效果

以下是我的部分代码:

if ( p1ScoreCount === inputScore.value) {
    p1Span.classList.add("green");
    gameOver = true;
    alert("Player 1 Wins!");
} 

else if ( p2ScoreCount === inputScore.value) {
    p2Span.classList.add("green");
    gameOver = true;
    alert("Player 2 Wins!");
}

if (gameOver === true) {
       p1Button.disabled = true;
       p2Button.disabled = true;
    }
1) 只要“P1Span”和“P2Span”等于输入字段的值,游戏就不会结束。我甚至尝试使用双重比较运算符,但仍然没有结果

2) 按下重置按钮仅将输入字段重置回其默认值5,但不会将分数重置为0

3) 由于某些原因,当通过单击箭头(fast)更改输入值时,会有很多延迟,并且更改并不总是反映在HTML中


如果有人对这些问题有任何意见,我将不胜感激。谢谢大家!

只是一些简单的更改

1)我在点击事件
if(p1ScoreCount==inputScore.value){…}

2)
p1Span.innerHTML=0;p2Span.innerHTML=0

3)这不一定是个问题,这是事件的返回时间
“更改”
,也许
“单击”
事件就是您要查找的

const p1Span=document.getElementById(“p1Span”);
const p2Span=document.getElementById(“p2Span”);
常量p1Button=document.getElementById(“p1”);
常量p2Button=document.getElementById(“p2”);
const inputScore=document.getElementById(“inputScore”);
const playToSpan=document.getElementById(“playToSpan”);
const resetButton=document.getElementsByTagName(“按钮”)[2];
让gameOver=false;
设p1ScoreCount=0;
设p2ScoreCount=0;
//玩家1/2按钮可在单击时将分数添加到跨度。
p1Button.addEventListener(“单击”,()=>{
p1ScoreCount++;
p1Span.textContent=p1ScoreCount;
if(p1ScoreCount==inputScore.value){
警惕(“玩家1赢”);
p1Span.className+=“绿色”;
p1Button.disabled=true;
p2Button.disabled=true;
//重置();
}
});
p2Button.addEventListener(“单击”,()=>{
p2ScoreCount++;
p2Span.textContent=p2ScoreCount;
if(p2ScoreCount==inputScore.value){
警惕(“玩家2赢”);
p2Span.className+=“绿色”;
p1Button.disabled=true;
p2Button.disabled=true;
}
});
//使用文本输入指定要播放的内容
inputScore.addEventListener(“单击”,()=>{
playToSpan.textContent=inputScore.value;
});
//重置按钮重置游戏
resetButton.addEventListener(“单击”,函数(){
重置();
});
函数重置(){
gameOver=false;
p1ScoreCount=0;
p2ScoreCount=0;
p1Span.innerHTML=0;
p2Span.innerHTML=0;
inputScore.value=5;
p1Span.classList.remove(“绿色”);
p2Span.classList.remove(“绿色”);
p1Button.disabled=false;
p2Button.disabled=false;
}
.green{
颜色:绿色;
}

0比0
玩到:5
一号玩家
球员二
重置

只是一些简单的更改

1)我在点击事件
if(p1ScoreCount==inputScore.value){…}

2)
p1Span.innerHTML=0;p2Span.innerHTML=0

3)这不一定是个问题,这是事件的返回时间
“更改”
,也许
“单击”
事件就是您要查找的

const p1Span=document.getElementById(“p1Span”);
const p2Span=document.getElementById(“p2Span”);
常量p1Button=document.getElementById(“p1”);
常量p2Button=document.getElementById(“p2”);
const inputScore=document.getElementById(“inputScore”);
const playToSpan=document.getElementById(“playToSpan”);
const resetButton=document.getElementsByTagName(“按钮”)[2];
让gameOver=false;
设p1ScoreCount=0;
设p2ScoreCount=0;
//玩家1/2按钮可在单击时将分数添加到跨度。
p1Button.addEventListener(“单击”,()=>{
p1ScoreCount++;
p1Span.textContent=p1ScoreCount;
if(p1ScoreCount==inputScore.value){
警惕(“玩家1赢”);
p1Span.className+=“绿色”;
p1Button.disabled=true;
p2Button.disabled=true;
//重置();
}
});
p2Button.addEventListener(“单击”,()=>{
p2ScoreCount++;
p2Span.textContent=p2ScoreCount;
if(p2ScoreCount==inputScore.value){
警惕(“玩家2赢”);
p2Span.className+=“绿色”;
p1Button.disabled=true;
p2Button.disabled=true;
}
});
//使用文本输入指定要播放的内容
inputScore.addEventListener(“单击”,()=>{
playToSpan.textContent=inputScore.value;
});
//重置按钮重置游戏
resetButton.addEventListener(“单击”,函数(){
重置();
});
函数重置(){
gameOver=false;
p1ScoreCount=0;
p2ScoreCount=0;
p1Span.innerHTML=0;
p2Span.innerHTML=0;
inputScore.value=5;
p1Span.classList.remove(“绿色”);
p2Span.classList.remove(“绿色”);
p1Button.disabled=false;
p2Button.disabled=false;
}
.green{
颜色:绿色;
}

0比0
玩到:5
一号玩家
球员二
重置