Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单选按钮+单击非单选按钮_Javascript - Fatal编程技术网

Javascript 单选按钮+单击非单选按钮

Javascript 单选按钮+单击非单选按钮,javascript,Javascript,我正在尝试为在线训练营创建一个测验。我试图做到这样,当用户点击一个正确或错误的单选按钮,然后点击下一个按钮,分数就会更新,下一个问题就会显示出来。我试图使用Javascript的第30-32行来实现这一点,但不太确定如何实现它。它当前正在阻止我的应用程序在未被注释掉时运行 这是我的HTML: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <link

我正在尝试为在线训练营创建一个测验。我试图做到这样,当用户点击一个正确或错误的单选按钮,然后点击下一个按钮,分数就会更新,下一个问题就会显示出来。我试图使用Javascript的第30-32行来实现这一点,但不太确定如何实现它。它当前正在阻止我的应用程序在未被注释掉时运行

这是我的HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="quiz.css">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript" src="quiz.js"></script>
    <title>Pokemon Quiz</title>
</head>
<body>
    <h1>Pokemon Quiz! Test your skill!</h1>
    <button id="reset" type="button">Reset Quiz</button>
    <form>
      <h3 class="anchor"></h3><br>
      <input type="radio" name="T/F" id="true">True<br>
      <input type="radio" name="T/F" id="false">False
      <br><button type="button" id="next">Next/Start</button><br>
    </form>
    <p>Score: <span id="score">0</span></p>
    <p>Question No. <span id="questionnum">0</span></p>
</body>
</html>
Javascript:

$( document ).ready(function() {
    //game();
    questionNumber = 0;
    score = 0;
    if (questionNumber < questions.length) {
        $('#next').click(function(){
        game();
        questionNumber ++;
        });
    };

    $('#reset').click(function(){
        neu();
        game();
    });

});

function neu() {
    questionNumber = 0;
    score = 0;
}

function game() {
    console.log(questionNumber);
    $("h3.anchor").html(questions[questionNumber]);

    //if radiobutton value == answers[questionNumber]

    if ((document.getElementById("true").checked && answers[questionNumber] == true) || (document.getElementById("false").checked && answers[questionNumber] == false) {
        score ++;
    }

/*
    if(document.getElementById("next").clicked == true) {
        if(document.getElementById("true").checked) {
            score++;
            console.log(score);
        }
        console.log(score);
        $(".anchor").html("There are 9 certified Pokemon League badges?");
    }
    */
}

//Use use question number to access array values (questions)
//consider using object instead of array to allow for boolean values
//var questions = [];
questions = ["Caterpie evolves into Metapod?",
"There are 9 certified Pokemon League badges?",
"Poliwag evolves 3 times?",
"Are thunder moves effective against ground-type Pokemon?",
"Pokemon of the same kind and level are not identical?",
"TM28 contains Tombstony?"];

answers = [true, false, false, false, true, false];

它当前阻止我的应用程序运行意味着什么?控制台中有错误吗?首先,没有全局问题编号,所以游戏在尝试使用该变量时应该会出现某种错误。
$( document ).ready(function() {
    //game();
    questionNumber = 0;
    score = 0;
    if (questionNumber < questions.length) {
        $('#next').click(function(){
        game();
        questionNumber ++;
        });
    };

    $('#reset').click(function(){
        neu();
        game();
    });

});

function neu() {
    questionNumber = 0;
    score = 0;
}

function game() {
    console.log(questionNumber);
    $("h3.anchor").html(questions[questionNumber]);

    //if radiobutton value == answers[questionNumber]

    if ((document.getElementById("true").checked && answers[questionNumber] == true) || (document.getElementById("false").checked && answers[questionNumber] == false) {
        score ++;
    }

/*
    if(document.getElementById("next").clicked == true) {
        if(document.getElementById("true").checked) {
            score++;
            console.log(score);
        }
        console.log(score);
        $(".anchor").html("There are 9 certified Pokemon League badges?");
    }
    */
}

//Use use question number to access array values (questions)
//consider using object instead of array to allow for boolean values
//var questions = [];
questions = ["Caterpie evolves into Metapod?",
"There are 9 certified Pokemon League badges?",
"Poliwag evolves 3 times?",
"Are thunder moves effective against ground-type Pokemon?",
"Pokemon of the same kind and level are not identical?",
"TM28 contains Tombstony?"];

answers = [true, false, false, false, true, false];