간단한 수학 게임을 위해 아래에 수정/편집 된 코드가 있습니다. 해결하고자하는 금액을 입력 한 다음 해결하십시오!수학 게임을 만들려고 시도합니다.
내가 지금 겪고있는 문제는 맨 끝에는 점수 만 표시된다는 것입니다.
점수를 표시하는 것뿐 아니라 해결하기 위해 입력 한 질문의 양을 표시하려고합니다. 따라서 올바른 "입력 된"점수의 "out of more"점수가 더 많습니다. 아래는 코드와 피들 링크입니다.
http://jsfiddle.net/justinw001/Mttw6/12/
$(function() {
var score = 0;
var questions = [];
$('#gen').click(function() {
score = 0;
questions = [];
var questionAmount = parseInt($('#inputElement').val(), 10);
for (var i = 0; i < questionAmount; i++) {
var q = {
x: Math.floor(Math.random() * 13),
y: Math.floor(Math.random() * 13)
};
questions.push(q);
}
nextQuest(questions.pop());
});
$('#sub').click(function() {
var ans, x, y;
if (questions.length >= 0) {
ans = parseInt($('#answer').val(), 10);
x = parseInt($('#input1').text(), 10);
y = parseInt($('#input2').text(), 10);
if (ans === x * y) {
score++;
}
nextQuest(questions.pop());
}
});
var nextQuest = function (q) {
if (q) {
$('#input1').text(q.x);
$('#input2').text(q.y);
$('#answer').val('');
$('#inputElement').val(questions.length);
} else {
$('#input1, #input2').text('');
$('#answer, #inputElement').val('');
alert(score);
}
};
});
어디서 붙어 있습니까? –
jsFiddle이 도움이 될 것입니다. – j08691
내가 묻고있는 질문 아래에는 상단에 피들 (Fiddle)이 있습니다. – user2918151