如何获得正确的测验分数? [英] How to get correct score of quiz ?

查看:73
本文介绍了如何获得正确的测验分数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手。以下是我的JavaScript代码的html文档。



我尝试过:



 <   div     class   =  start  >  
< h1 > 欢迎使用英语学生< / h1 >
< a class = btn href = > 使用入门< / a >
< / div >

< div class = 测验 >


< a class = sub HREF = > 提交< / a >
< / div >

< div class = 摘要 >
< h2 > 摘要屏幕< / h2 >
< p > 恭喜你正确得分x! < / p >
< a class = rst href = > 重新启动测验< / a >
< / div >





  var  questions = [
{
title: 我喜欢板球。,
回答: 我不喜欢板球。
},

{
title: 他很聪明。
回答: 他不聪明。
},

{
title: 她唱得很好。
回答: 她唱得不好。
},

{
title: 你是骗子。
回答: 你不是骗子。
},

{
title: 他们是来吧。
回答: 他们不会来。

},

];


得分= 0 ;
currentQuestion = 0 ;

$(' document')。ready( function (){
$(' .start a')。click( function (e){
e.preventDefault();
$(' .start')。hide();
$(' 。quiz')。show();
showQuestion();
});

$(' .output')。keyup( function ( e){
if (e.keyCode === 13 ){
$(' 。sub')。click();
}
} );
});


function showQuestion(){
question = questions [currentQuestion];
$(' .input')。val(question.title);
$(' 。quiz')。html();
for var i = 0 ; i< question.answer.length; i ++){
}
}

function checkAnswer( ){
question = questions [currentQuestion];
out = $(' 。output )VAL();
if (out == questions [currentQuestion] .answer){
score ++;
}
currentQuestion ++;
if (currentQuestion> = questions.length){
showSummary();
} else {
showQuestion();
}

$(' 。sub')。点击( function (){
$(' .output')。val(' ');
});
}


function showSummary(){
$(' .quiz')。hide();
$(' 。summary')。show();
$(' 。summary p')。text( 恭喜你得分 +得分+ out of +
questions.length + 正确!);

}

function restartQuiz(){
$(' 。summary a')。click( function (e){
e.preventDefault();
$(' 。summary')。hide( );
$(' .quiz')。show();
currentQuestion = 0 ;
showQuestion();
});
}

解决方案

' document')。ready( function (){


' 。启动')。点击( function (e) {
e.preventDefault();


' .start )隐藏();

I am a newbie. The following is the html document to my JavaScript code.

What I have tried:

<div class="start">
    <h1> Welcome to English Pupils </h1>
    <a class="btn" href="#"> Get Started </a>
</div>

<div class="quiz">
    
    
    <a class="sub" href="#"> Submit </a>
</div>

<div class="summary">
    <h2> Summary Screen </h2>
    <p> Congrats you scored x out of y correct ! </p>
    <a class="rst" href="#"> Restart Quiz </a>
</div>



var questions = [
    {
        title: "I like cricket.",
        answer: "I do not like cricket."
    },
    
    {
        title: "He is smart.",
        answer: "He is not smart."
    },
    
    {
        title: "She sings well.",
        answer: "She does not sing well."	
    },
    
    {
        title: "You are a cheat.",
        answer: "You are not a cheat."
    },
    
    {
        title: "They are coming.",
        answer: "They are not coming."
        
    },
    
];


let score = 0;
let currentQuestion = 0;

$('document').ready(function () {
    $('.start a').click(function (e) {
        e.preventDefault();
        $('.start').hide();
        $('.quiz').show();
        showQuestion();
    });
    
    $('.output').keyup(function (e) {
        if (e.keyCode === 13) {
            $('.sub').click();
        }
    });
});


function showQuestion() {
    let question = questions[currentQuestion];
    $('.input').val(question.title);
    $('.quiz').html();
    for (var i = 0; i < question.answer.length; i++) {
    }
}

function checkAnswer() {
    let question = questions[currentQuestion];
    let out = $('.output').val();
    if (out == questions[currentQuestion].answer) {
        score++;
    }
    currentQuestion++;
    if (currentQuestion >= questions.length) {
        showSummary();
    } else {
        showQuestion();
    }
    
    $('.sub').click(function () {
        $('.output').val('');
    });
}


function showSummary() {
    $('.quiz').hide();
    $('.summary').show();
    $('.summary p').text("Congrats you scored " + score + " out of " + 
    questions.length + " correct !");
    
}

function restartQuiz() {
    $('.summary a').click(function (e) {
        e.preventDefault();
        $('.summary').hide();
        $('.quiz').show();
        currentQuestion = 0;
        showQuestion();
    });
}

解决方案

('document').ready(function () {


('.start a').click(function (e) { e.preventDefault();


('.start').hide();


这篇关于如何获得正确的测验分数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆