【问题标题】:How to fix a scoreboard?如何修复记分牌?
【发布时间】:2022-08-17 19:58:25
【问题描述】:

我怎样才能让我的记分牌在时间上达到 +1 分,而不是 +10?

let placar = setInterval(updated);
let pontuacao = 0;

function updated(){
    var pontos = document.getElementById(\'score\');
    pontos.innerHTML = \"score: \" + pontuacao++;
    clearInterval(placar);
}

马里奥自制游戏

  • 你为什么还要使用间隔?
  • 如果你要使用一个区间,你应该指定一个区间值。
  • 如果它被调用一次,代码不可能将分数提高 10

标签: javascript html css


【解决方案1】:

包装你的增量 int var

tho,我不确定你为什么在那个函数中使用clearInterval。

let placar = setInterval(updated);
let pontuacao = 0;

function updated(){
    var pontos = document.getElementById('score');
    pontos.innerHTML = "score: " + (pontuacao++).toString();
    clearInterval(placar);
}

【讨论】:

  • 不 ... ++ 递增 1,而不是 10
猜你喜欢
  • 1970-01-01
  • 2013-06-29
  • 2022-06-14
  • 1970-01-01
  • 2014-01-08
  • 1970-01-01
  • 2019-08-29
  • 1970-01-01
  • 2020-10-19
相关资源
最近更新 更多