- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
功能:
我正在尝试创建一个有 5 次尝试的测验,其中每个问题页面都是从每个类别中显示的随机问题。
因此,如果用户答对了每个问题,下一个问题将淡入,如果用户在 5 次尝试中有 3 次答对了 3 个问题,他们将被导航到 gameWin 页面。否则,如果用户已完成所有 5 次尝试,它会将用户导航到 GameOver 页面。
问题:
此时,在用户完成所有 5 次尝试后,以下错误消息显示在我的 console.log 中 => Uncaught RangeError: Maximum call stack size exceeded.
我想寻求帮助,以解决以下有关超出调用堆栈大小的问题。
代码:
function showQuestion() {
//Question list shown is more than 5, show game over
if (GamePage_question_list.length > 5) {
GameOver();
} else {
//Randomise Each Category Questions
//Randomise Category_A Question
random_Question_CategoryA = Math.floor(Math.random() * CategoryA_Questions.length);
//Randomise Category_B Question
random_Question_CategoryB = Math.floor(Math.random() * CategoryB_Questions.length);
//Randomise Category_C Question
random_Question_CategoryC = Math.floor(Math.random() * CategoryC_Questions.length);
//Randomise Category_D Question
random_Question_CategoryD = Math.floor(Math.random() * CategoryD_Questions.length);
//Display random question
random_Question = Math.floor(Math.random() * GameQuestion.length);
var exist = false;
for (i = 0; i < GamePage_question_list.length; i++) {
if (GamePage_question_list[i] == (random_Question_CategoryA + "")) {
exist = true;
} else if (GamePage_question_list[i] == (random_Question_CategoryB + "")) {
exist = true;
} else if (GamePage_question_list[i] == (random_Question_CategoryC + "")) {
exist = true;
} else if (GamePage_question_list[i] == (random_Question_CategoryD + "")) {
exist = true;
} else if (GamePage_question_list[i] == (random_Question + "")) {
exist = true;
}
}
Game_wait = false;
if (exist == false) {
//Display Question from each category after each question has been answered
if (GamePage_question_list.length == 0) {
console.log("Questions:" + CategoryA_Questions[random_Question_CategoryA]);
GamePage_question_list.push(random_Question_CategoryA + "");
$("#GamePage_question").html(CategoryA_Questions[random_Question_CategoryA]);
answerList = CategoryA_Answers[random_Question_CategoryA];
$("#GamePageAnswer_1").attr("src", answerList[0]);
$("#GamePageAnswer_2").attr("src", answerList[1]);
console.log("Answers:" + answerList);
} else if (GamePage_question_list.length == 1) {
GamePage_question_list.push(random_Question_CategoryB + "");
$("#GamePage_question").html(CategoryB_Questions[random_Question_CategoryB]);
answerList = CategoryB_Answers[random_Question_CategoryB];
$("#GamePageAnswer_1").attr("src", answerList[0]);
$("#GamePageAnswer_2").attr("src", answerList[1]);
} else if (GamePage_question_list.length == 2) {
GamePage_question_list.push(random_Question_CategoryC + "");
$("#GamePage_question").html(CategoryC_Questions[random_Question_CategoryC]);
answerList = CategoryC_Answers[random_Question_CategoryC];
$("#GamePageAnswer_1").attr("src", answerList[0]);
$("#GamePageAnswer_2").attr("src", answerList[1]);
} else if (GamePage_question_list.length == 3) {
GamePage_question_list.push(random_Question_CategoryD + "");
$("#GamePage_question").html(CategoryD_Questions[random_Question_CategoryD]);
answerList = CategoryD_Answers[random_Question_CategoryD];
$("#GamePageAnswer_1").attr("src", answerList[0]);
$("#GamePageAnswer_2").attr("src", answerList[1]);
} else if (GamePage_question_list.length == 4) {
GamePage_question_list.push(random_Question + "");
$("#GamePage_question").html(GameQuestion[random_Question]);
answerList = GameAnswer[random_Question];
$("#GamePageAnswer_1").attr("src", answerList[0]);
$("#GamePageAnswer_2").attr("src", answerList[1]);
}
} else {
showQuestion();
}
}
}
function select_answer(flag) {
if (Game_wait == false) {
Game_wait = true;
var currentQuestionIndex = GamePage_question_list[GamePage_question_list.length - 1];
var CategoryA_correctAnswer = CategoryA_CorrectAnswers[parseInt(currentQuestionIndex)];
var CategoryA_POPUP_Answer = CategoryA_PopUpAnswers[parseInt(currentQuestionIndex)];
var CategoryB_correctAnswer = CategoryB_CorrectAnswers[parseInt(currentQuestionIndex)];
var CategoryB_POPUP_Answer = CategoryB_PopUpAnswers[parseInt(currentQuestionIndex)];
var CategoryC_correctAnswer = CategoryC_CorrectAnswers[parseInt(currentQuestionIndex)];
var CategoryC_POPUP_Answer = CategoryC_PopUpAnswers[parseInt(currentQuestionIndex)];
var CategoryD_correctAnswer = CategoryD_CorrectAnswers[parseInt(currentQuestionIndex)];
var CategoryD_POPUP_Answer = CategoryD_PopUpAnswers[parseInt(currentQuestionIndex)];
var correctAnswer = GameCorrectAnswer[parseInt(currentQuestionIndex)];
var POPUP_Answer = GamePopUpAnswer[parseInt(currentQuestionIndex)];
console.log("flag_answer chosen:" + flag);
//Show the POPUP Correct answer
//THIS IS THE PART WHERE THE CORRECT ANSWER WILL SHOW IF THE USER ANSWERS EACH QUESTION WRONGLY
if (GamePage_question_list.length == 1) {
console.log("CategoryA_correctAnswer" + CategoryA_correctAnswer);
console.log("A");
} else if (GamePage_question_list.length == 2) {
console.log("CategoryB_correctAnswer" + CategoryB_correctAnswer);
console.log("B");
} else if (GamePage_question_list.length == 3) {
console.log("CategoryC_correctAnswer" + CategoryC_correctAnswer);
console.log("C");
} else if (GamePage_question_list.length == 4) {
console.log("CategoryD_correctAnswer" + CategoryD_correctAnswer);
console.log("D");
} else if (GamePage_question_list.length == 5) {
console.log("GameCorrectAnswer" + GameCorrectAnswer);
console.log("E");
}
}
}
function GameOver() {
idleTime = 0;
console.log("GameOver");
setTimeout(function() {
location.reload();
}, 5000);
}
<!-- Original Question -->
<div id="GamePage_question" style="position:absolute; z-index:99; top:460px; left:160px; margin:auto; color:#FFFFFF; font-size:60px; font-family: Calibrib; width:800px; text-align: center;"></div>
<!-- Answer-Original-Choice List -->
<img id="GamePageAnswer_1" style="position:absolute; z-index:3; top:1100px; left:260px; margin:auto;" />
<img id="GamePageAnswer_2" style="position:absolute; z-index:3; top:1300px; left:260px;" />
<!-- Selection answer -->
<img src="lib/image/transparent.png" class="transparentBg" style="position:absolute; z-index:4; top:1100px; left:0px; margin:auto; width:1080px; height:150px; border:1;" onclick="select_answer(1);" />
<img src="lib/image/transparent.png" class="transparentBg" style="position:absolute; z-index:4; top:1300px; left:0px; margin:auto; border:1; width:1080px; height:150px;" onclick="select_answer(2);" />
最佳答案
我基本上猜测这里的 else 子句> if (exist == false)
导致对 showQuestion
的相同无限调用(如@JonasGrumann 所评论)而 exist
是除 false
之外的值(正如@Reddy 评论的那样,调用循环导致此 RangeError
)。 GamePage_question_list
永远不会达到@FK82 评论的第六个长度,因此 if (GamePage_question_list.length > 5)
的 if
子句永远不会执行,但是else 子句,其中 showQuestion
在 if (exist == false)
的 else 子句中永远被调用(我认为 5
长度应该在此处更具编程性:4
)。
基本解决方案是更新此 GamePage_question_list.length > 5
条件,其中 bigger than 运算符可以是 >=
或 5
可以是 4
,检查长度 getter 是否返回大于/等于/等于 5 的值。
关于javascript - 经历 "Uncaught RangeError: Maximum call stack size exceeded",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40717921/
考虑一下,我们在具有整数弧容量的有向网络中有一个非整数最大流。 是否有算法可以将这个流量转化为整数最大流量? 它的运行时间是多少? 这不是作业问题。 最佳答案 如果您正在寻找具有积分弧容量的最大 s-
我有一个可以接受 byte[] 的 WCF 服务。我正在使用 HttpClient 创建客户端并收到以下错误。我在网上看到你必须在服务器和客户端上设置 readerQuotas,但是如何在 HttpC
我有一个如下所示的数据框: df = pd.DataFrame({'A':[100,300,500,600], 'B':[100,200,300,400],
我开始使用 cocoapi评估使用 Object Detection API 训练的模型。在阅读了解释平均精度 (mAP) 和召回率的各种来源后,我对 cocoapi 中使用的“最大检测”参数感到困惑
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: Size-limited queue that holds last N elements in Java Java
您好,我需要帮助制作以下算法: 假设一个二维空间域,具有 xmax、xmin、ymin、ymax,空间中有“n~10,000”个点。 浏览点位置列表。 当框中的点数达到最大数量(假设为 10 个)时,
我在 Android 应用程序中有一个类,它包含一个字节数组作为纹理的数据源。我使用帧缓冲区将一些东西渲染到该纹理上,然后在屏幕上渲染该纹理。这非常有效。 但是,我只能使用 151 个纹理来执行此操作
系统调用中可以传递多少个参数?我检查了内核文件 /asm/unistd.h,没有看到包含超过 4 个参数的系统调用。 最佳答案 这取决于您使用的架构。对于 i386,系统调用号旁边最多有 6 个参数。
题目地址:https://leetcode-cn.com/problems/maximum-average-subtree/ 题目描述 Given the root of a binary tre
题目地址:https://leetcode.com/problems/sliding-window-maximum/ 题目描述 Given an array nums, there is a sl
题目地址:https://leetcode-cn.com/problems/maximum-distance-in-arrays/ 题目描述 Given m arrays, and each ar
题目地址:https://leetcode.com/problems/maximum-average-subarray-i/description/open in new window 题目描述
题目地址:https://leetcode.com/problems/third-maximum-number/description/ 题目描述 Given a non-empty array
我有一个很难重现的错误。另外,有人告诉我写日志文件是一种安全责任。所以我想在异常中尽可能多地捕捉。 我找不到任何说明 C# 异常的最大长度是多少的地方。 我想粘贴一条 XML 消息(1 或 2K),也
是否可以限制 QML 应用的最大 FPS? 我在低端 iten atom 硬件中获得 60FPS 和 30% 的 CPU 使用率使用 win32 Angle 驱动程序(openGL 软件无法使用),我
我已启用 SeriLog(最新版本)自记录功能,并且看到数百条消息说 Maximum destructuring depth reached 不知道这意味着什么以及这是否是我需要担心的问题。 有谁知道
我有一个具有两个属性的模型(我只显示两个,因为只需要这两列) 我的模型 place_id ---------------------- user_id 1 ----------------------
考虑以下情况:要设置一个群集,其中每台计算机都具有32G GB的RAM。和16个CPU核心 如何根据信息(32G GB RAM和16 CPU CORE)确定以下参数 ) yarn.scheduler.
完成如下函数定义: -- maxi x y returns the maximum of x and y 我应该不使用 Haskell 中的“最大”函数来完成这个任务。 maxi :: Int
Haskell 标准库中是否有与 maximum 等效的安全值? *Main Control.Monad.State Data.List> maximum [] *** Exception: Prel
我是一名优秀的程序员,十分优秀!