当我第二次运行我的应用程序时,结果没有显示

Result is not showing when I run my app second time

本文关键字:结果 显示 应用程序 第二次 运行 我的      更新时间:2023-09-26

我有这个测验应用程序,当我第一次运行它时它会显示结果,但是当我再次单击"播放"并再次运行该应用程序时,它没有显示结果。我知道我在遵循代码时遇到问题,但无法弄清楚。请帮忙 -

//This function is for reseting the quiz
    var resetQuiz = function() {
            if (resetCounter++ > 1 || quizOver || confirm('Are you sure you want to reset the quiz?')) {
                counter = 0;
                quizOver = false;
                results = {count: 0, answers: [], currentScore: 0};
                scoreNode.addClass('no_score').text('');
                questionBlock.show();
                nextQuestion();
            }
    };
    //This function handle the results
    var showResults = function() {
            answersBlock.empty();
            questionBlock.hide();
            showResult.text('You answered ' + results.currentScore + '% of '
                + 'the questions correctly.');
            quizOver = true;
            actionButton.text('Play again');
    };

完整的应用程序在这里 - http://jsfiddle.net/varunksaini/J5qVd/

var buttonAction = function() {中,单击"再次播放"后,您正在执行showResult.hide();,这会将其设置为具有display:none

但是,您永远不会在 showResults() 函数中调用showResult.show();。 所以它仍然与display:none. 您只需要在更改文本后调用showResults.show();

var showResults = function() {
        answersBlock.empty();
        questionBlock.hide();
        showResult.text('You answered ' + results.currentScore + '% of '
            + 'the questions correctly.');
        quizOver = true;
        showResult.show(); //Show the results if they have been hidden
        actionButton.text('Play again');
};