私はこのコードを書きました:
$(".awesome").click(function () {
        var toStore = $("input[name=name]").val();
        if (/^[A-Za-z]+ [A-Za-z]+$/.test(toStore)) {
            $("#contain").children().fadeOut(1000);
            $("#contain").delay(1000).queue(function () {
                $("#contain").append("<h1>Welcome to My Quiz : " + toStore + "</br>" +
                    "Youll Get 10 Questions To Answer </br> " +
                    "Here Is the First One:Who is Prime Minister of the United Kingdom? </h1>");
                var allQuestions = [
                    {question: "Who is Prime Minister of the United Kingdom?",
                        choices: ["David Cameron",
                            "Gordon Brown",
                            "Winston Churchill",
                            "Tony Blair"],
                        correctAnswer: 0}
                ];
                $("#contain").append("<form><input type='radio' name='ans1' value='David Cameron'>David Cameron</br>" +
                    " <input type='radio' name='ans1' value='Gordon Brown'>Gordon Brown</br>" +
                    "<input type='radio' name = 'ans1' value = 'Winston Churchill' > Winston Churchill </br>" +
                    "<input type='radio' name='ans1' value='Tony Blair'>Tony Blair</br>" +
                    "<input type='submit' value='Submit' name='submit'></form>");
                $("input[name=submit]").click(function () {
                    var correctAnswer;
                    if ($("input[name=ans1]").val()) {
                        var x = "choices";
                        allQuestions[x] = "David Cameron";
                        for (var x in allQuestions) {
                            return correctAmswer = false;
                            if (allQuestions[x] === "David Cameron") {
                                return correctAnswer = true;
                            } else {
                                return correctAnswer = false;
                            }
                        }
                    }
                });
            });
        } else {
            alert("You Must Put a Valid Name");
        }
    });
});
ご覧のとおり、「allQuestions」というオブジェクトがあります。これで、「質問」「選択肢」「正解」の 3 つのプロパティができました。その後、送信ボタンをクリックすると、入力 name="ans1" の値がチェックされ、オブジェクト "allQuestions" のすべての選択肢がループされます。答えが "David Cameron" の場合、正しい答えを 0 ではなく 1 に保存する必要があります。それ以外の場合、正しい回答を保存したくありません。後でさらに質問があるため、0のままです。その方法について何か提案はありますか?