HTML/Javascript测试应用程序运行缓慢/崩溃

HTML/Javascript测试应用程序运行缓慢/崩溃,javascript,html,css,Javascript,Html,Css,我有一个问题,我的其他充分发挥测验游戏。在大约5到6个(10个问题中的5个)问题之后,似乎出现了崩溃/加载缓慢的问题。这很奇怪,因为如果我在一秒钟内回答所有问题(不现实,但要进行错误检查),就没有问题了。但只要我花“正常”的时间回答问题,事情就会变慢,最终会崩溃/卡住 我尝试过删除动画和调整我的JS流,但没有效果。如果有人有任何想法,我们将不胜感激 以下是指向网站本身的链接: 以下是回购协议的链接: const question=document.getElementById(“问题”);

我有一个问题,我的其他充分发挥测验游戏。在大约5到6个(10个问题中的5个)问题之后,似乎出现了崩溃/加载缓慢的问题。这很奇怪,因为如果我在一秒钟内回答所有问题(不现实,但要进行错误检查),就没有问题了。但只要我花“正常”的时间回答问题,事情就会变慢,最终会崩溃/卡住

我尝试过删除动画和调整我的JS流,但没有效果。如果有人有任何想法,我们将不胜感激

以下是指向网站本身的链接:

以下是回购协议的链接:

const question=document.getElementById(“问题”);
const choices=Array.from(document.getElementsByClassName(“choice_utext”);
const scoreText=document.getElementById('score');
常量计时器=document.getElementById(“计时器”);
const game=document.getElementById(“游戏”);
常量加载器=document.getElementById(“加载器”);
const gameDemobility=window.location.search.replace(“?mode=”,”);
/*开始比赛*/
//游戏机制
让currentQuestion={};
让回答为真;
分数=0;
设提问计数器=0;
设availableequestions={};
让fetchingData=true;
让接受答案=真;
//从API获取数据
取回(`https://opentdb.com/api.php?amount=10&category=12&difficulty=${gameconstibility}&type=multiple`)
。然后(res=>{
返回res.json();
})
//从API获取问题数据并格式化以供使用
.然后((加载的问题)=>{
问题=loadedQuestions.results.map((loadedQuestion)=>{
常量格式化问题={
问题:loadedQuestion.question,
};
//获取答案数据并为正确答案和不正确答案选择随机位置
const answerChoices=[…加载的问题。回答不正确];
formattedQuestion.answer=Math.floor(Math.random()*4)+1;
应答器(
格式化的问题。答案-1,
0,
加载的问题。正确的答案
);
回答选择。forEach((选择,索引)=>{
格式化问题['choice'+(索引+1)]=选项;
});
返回格式化问题;
});
//计时器
//函数在当前时间结束或新问题开始时启动计时器
函数restartineval(){
设秒=document.getElementById(“计时器”).textContent;
让倒计时=设置间隔(函数(){
秒--;
//新的问题计时器重新启动功能
选项。forEach((选项)=>{
choice.addEventListener('click',(e)=>{
清除间隔(倒计时);
timer.innerText=“30”;
restartineval();
});
});
//定时器达到零重启功能
document.getElementById(“计时器”).textContent=seconds;
如果(秒){
game.classList.remove(“隐藏”);
loader.classList.add(“隐藏”);
startGame();
restartineval();
}, 1000);
})
.catch((错误)=>{
控制台错误(err);
});
//用于加载游戏页面的基本设置
常量startGame=()=>{
问讯员=0;
得分=0;
availableQuestions=[…问题];
getNewQuestion();
};
//根据gae难度给出具体分数
const levelScore=游戏难度==“简单”?10
:游戏难度==“中等”?20
: 30;
常量maxQuestions=10;
让baseUrl=”https://louparker.github.io/random-music-quiz";
//检查答案是否正确
选项。forEach((选项)=>{
choice.addEventListener('click',(e)=>{
如果(!takingAnswers)返回;
接受回答=错误;
const selectedChoice=e.target;
const selectedAnswer=selectedChoice.dataset.number;
康斯特classToApply=
selectedAnswer==currentQuestion.answer?“正确”:“不正确”;
如果(classToApply==“正确”){
递增分数(levelScore);
}
selectedChoice.parentElement.classList.add(classToApply);
设置超时(()=>{
selectedChoice.parentElement.classList.remove(classToApply);
getNewQuestion();
}, 1000);
});
});
//将指定的分数添加到分数元素
常量增量分数=(num)=>{
分数+=num;
scoreText.innerHTML=分数;
};
//获取新问题数据并为gameover页面分配分数
const getNewQuestion=()=>{
如果(availableQuestions.length==0 | |提问计数器>=maxQuestions){
setItem(“mostRecentScore”,score);
return window.location.replace(`${baseUrl}/gameover.html?mode=${game难点}`);
}
问句器++;
const questionIndex=Math.floor(Math.random()*availableequestions.length);
currentQuestion=availableQuestions[questionIndex];
question.innerHTML=currentQuestion.question;
选项。forEach((选项)=>{
常量编号=choice.dataset.number;
choice.innerHTML=currentQuestion['choice'+number];
});
拼接(问题索引,1);
接受回答=正确;
};

游戏

30

时间

0

分数