簡単なことを見逃していると確信していますが、正解が選択されているかどうかに基づいてスコアが正しくカウントされていません。その多肢選択式クイズ。コードは別の人が書いたものなので、一人で考えてみてください!何か案は?
var Question = function(Text){
this.Question = Text;
this.Answers = [];
this.addAnswer = function(Answer, Correct){
if(typeof Correct == 'undefined') Correct = false;
else Correct = Correct == true;
this.Answers.push({"Answer":Answer, "Correct":Correct});
};
this.checkAnswer = function(Index){
if(typeof this.Answers[Index] == 'undefined') return false;
return this.Answers[Index].Correct;
};
};
var Questions = [];
var q;
var Score = 0;
var CurrentQuestion = -1;
var nextQuestion = function()
{
++CurrentQuestion;
if(typeof Questions[CurrentQuestion] == 'undefined') return false;
var Question = Questions[CurrentQuestion];
$('#QuestionIndex').html(Numbers[CurrentQuestion]);
$('#QuestionsRemaining').html((Questions.length-CurrentQuestion-1));
$('#Question').html(Question.Question);
$('#Answers').html('');
for(var t in Question.Answers)
{
i = t;
t = Question.Answers[t];
var Div = $('<div class="answer"></div>');
$(Div).append('<span class="radioContainer"><input type="radio" name="Answer" id="answer_'+ i +'"></span> ');
$(Div).append($('<label for="answer_' + i + '" />').html(t.Answer));
$('#Answers').append(Div);
}
$("input[type='radio']").change(function(){
$('.radioContainer').css('background-image', 'none');
attr = $(this).attr('checked');
if(typeof attr !== 'undefined' && attr !== false)
{
$(this).parent().css('background-image', 'url("http://dev.clickymedia.co.uk/fbart/wp-content/themes/artbook/img/tick.png")');
}
});
return true;
}
//Returning false should stop the user from progressing to the next question.
var checkCurrentAnswer = function()
{
if(typeof Questions[CurrentQuestion] == 'undefined') return false;
var i = $('#Answers input:checked').parent().index();
if(i < 0) return false;
if(Questions[CurrentQuestion].checkAnswer(i) == true) Score++;
return true;
}
q = new Question("Which famous film star did Pop artist Andy Warhol make more portraits of than any other?");
q.addAnswer('Marilyn Monroe', true);
q.addAnswer('Sophia Loren');
q.addAnswer('Audrey Hepburn');
q.addAnswer('Doris Day');
Questions.push(q);
q = new Question("The Mona Lisa, Leonardo da Vinci's magnum opus, draws crowds into which famous European museum?");
q.addAnswer('The Musée du Louvre, Paris', true);
q.addAnswer('The Tate Britain, London');
q.addAnswer('The National Gallery, Berlin');
q.addAnswer('The Uffizi Gallery, Florence');
Questions.push(q);
$(function(){
nextQuestion();
$('#nextQuestion').bind('click', function(){
if(checkCurrentAnswer())
{
if(nextQuestion())
{
}else{ //End of examination! - Put your pens and pencils down.
$('#QuestionBook .FinalLeft .Score').html(Score + '/' + Questions.length);
$('#QuestionBook .FinalLeft .Message').html(Message);
$('#QuestionBook .QuestionContainer, #QuestionBook .AnswersContainer').hide();
$('#QuestionBook .FinalLeft, #QuestionBook .FinalRight').show();
}
}
});
});