Javascript 是什么原因导致此错误?我如何修复它?
我正在尝试用html和js制作一个游戏,在这个游戏中,屏幕上显示的单词要么是新的,要么是以前显示过的,你需要按正确的按钮(“看到”或“新”),否则你会失去生命 我的问题是,目前决定你是否会失去生命的单词是你按下按钮后出现的单词,因为你无法提前知道下一个单词,所以游戏无法进行Javascript 是什么原因导致此错误?我如何修复它?,javascript,html,Javascript,Html,我正在尝试用html和js制作一个游戏,在这个游戏中,屏幕上显示的单词要么是新的,要么是以前显示过的,你需要按正确的按钮(“看到”或“新”),否则你会失去生命 我的问题是,目前决定你是否会失去生命的单词是你按下按钮后出现的单词,因为你无法提前知道下一个单词,所以游戏无法进行 var word_bank=[“test1”、“test2”、“test3”、“test4”、“test5”、“test6”、“test7”、“test8”、“test9”、“test10”、“test11”、“test1
var word_bank=[“test1”、“test2”、“test3”、“test4”、“test5”、“test6”、“test7”、“test8”、“test9”、“test10”、“test11”、“test12”、“test13”、“test14”、“test15”];
var old_words=[];
var dec=世界银行;
var=3;
函数updateLives(){
document.getElementById(“lives”).innerHTML=“lives:”+lives;
}
功能事物(五){
var rndn=Math.floor(Math.random()*(1-0+1))+0;
如果(rndn==1){
var dec=世界银行
}否则{
var dec=旧单词
}
var word=dec[Math.floor(Math.random()*dec.length)];
document.getElementById(“word”).textContent=word;
如果(v==1){
if(旧单词,包括(单词)){
}
否则{
--生活
updateLives();
}
}
否则{
if(旧单词,包括(单词)){
--生活
updateLives();
}
}
旧单词。推(单词);
变量forDeletion=[word];
word\u bank=word\u bank.filter(项=>!forDeletion.includes(项))
};
var word=dec[Math.floor(Math.random()*dec.length)];
document.getElementById(“word”).textContent=word;
updateLives();
旧单词。推(单词);
变量forDeletion=[word];
word\u bank=word\u bank.filter(item=>!forDeletion.includes(item))
看到
新的
test10
功能中,您正在为下一轮生成一个单词,比如说test2
,同时您正在为该单词(test2
)判断玩家,而不是test10
test10
保存在变量中。然后,当用户采取行动时,您首先使用此变量对其进行评估。最后,生成下一轮单词
查看下面的脚本以获取一些参考
const liveSconteElement=document.getElementById(“lives”);
const wordElement=document.getElementById(“word”);
const scoreElement=document.getElementById(“分数”);
const playreach=document.getElementById(“playAgainBtn”);
const playBtns=document.getElementById(“playBtns”);
const wordsBank=[
“测试1”,“测试2”,“测试3”,“测试4”,“测试5”,“测试6”,“测试7”,“测试8”,“测试9”,“测试10”,“测试11”,“测试12”,“测试13”,“测试14”,“测试15”,“测试16”
];
让oldWords=[];
让生命=3;
让分数=-1;
让当前单词=”;
函数updateLives(){
livescontelement.innerHTML=“生活:”+生活;
如果(生活似乎这就是你要找的
var word_bank=[“test1”、“test2”、“test3”、“test4”、“test5”、“test6”、“test7”、“test8”、“test9”、“test10”、“test11”、“test12”、“test13”、“test14”、“test15”];
var old_words={};
让生命=3;
分数=0;
函数updateLives(){
document.getElementById(“lives”).innerHTML=`lives:${lives}分数:${Score}`;
}
函数getRandomWord(){
const rndm=Math.floor(Math.random()*字长);
返回单词_bank[rndm];
}
函数displayNewWord(){
const word=getRandomWord();
document.getElementById(“word”).textContent=word;
}
功能事物(五){
const currentWord=document.getElementById(“word”).textContent;
if((v==1&&!旧单词[currentWord])| |(v==0&&旧单词[currentWord])){
--生活;
}否则{
++得分;
}
updateLives();
如果(!活着){
document.getElementById(“游戏容器”).textContent='game over!';
返回;
}
旧词[当前词]=真;
displayNewWord();
};
displayNewWord();
updateLives();
看到
新的