我有一个学校项目,我们正在制作一个没有 UI 的小型 JavaScript 游戏;这意味着我们只能使用提示、警报或其他弹出脚本。
游戏应该可以运行,至少在我将其与模块分开之前它可以运行。这是一个简单的数学游戏,用户得到随机的+,问题并且必须正确回答
问题
我似乎无法向用户提供任何提示。我也无法在 chrome 开发工具中调试它,你能立即看到任何看起来不对的地方吗?非常感谢您的帮助:)
这是 JSfiddle
这是我们的代码,我只发布了重要部分——我省略了 index.html 和 Mathgame.js,因为它们看起来很完美,而且它们不包含很多代码。
MathGame.logic.js
mathGame.logic = (function() {
"use strict";
var createQuestion, getQuestion;
createQuestion = function() {
var tal1, tal2;
tal1 = Math.ceil(Math.random() * 10);
tal2 = Math.ceil(Math.random() * 10);
return {
tal1: tal1,
tal2: tal2,
result: function() {
return tal1 + tal2;
}
};
};
getQuestion = function() {
return createQuestion();
};
return {
getQuestion: getQuestion
};
}());
MathGame.play.js
mathGame.play = function() {
"use strict";
var question, guess, answer, correct, questionGuess;
// Starts game for user
mathGame.ui.startCountDown();
// Starts the timer in .logic
// mathGame.logic.startCountDown();
// Get random math
question = mathGame.logic.getQuestion();
// Send random math to User
questionGuess = mathGame.ui.askMathQuestion(question.tal1, question.tal2);
// The users guess
guess = mathGame.ui.returnMathGuess;
// See if the question is the same as the guess
correct = (question() === guess);
// Show the user how it went
mathGame.ui.showResult(correct, guess, question);
##Mathgame.ui.js##
mathGame.ui = {
startCountDown: function() {
"use strict";
// Visa ready set go
alert("READY");
alert("SET");
alert("GO");
},
askMathQuestion: function() {
"use strict";
prompt("askMathQuestion");
//shows a math question to user
// return Number(prompt(value1 + symbol + value2));
// e.g. value1 = 12
// value2 = 13
// symbol = "+"
// 12 + 13
// return user guess
},
returnMathGuess: function() {
"use strict";
},
showResult: function() {
"use strict";
}
};