Проверка значений от радиопроизводительной кнопкиJquery

Программирование на jquery
Ответить Пред. темаСлед. тема
Anonymous
 Проверка значений от радиопроизводительной кнопки

Сообщение Anonymous »

Итак, у меня было это работа вчера вечером, это 10 вопросов. Я сделал несколько ревизий сегодня, и теперь, когда я нажимаю, чтобы проверить ответ, я потерял функциональность, которая отображалась бы в Jumbotron, был ли ответ правильным или нет. Продолжить следующий вопрос по -прежнему удаляет и репулирует список. Просто кнопка, чтобы проверить вопрос Ответ, сломлен. Вот ссылка на JSFiddle: < /p>

Код: Выделить всё

$(document).ready(function() {

// Create array to traverse so that on clicking submit, the current question
//is deleted, and the next question in the array is loaded.
var questionsArray = [];

//Create counters for both correct answers and current question
var correctAnswers = 0;
var currentQuestion = 0;

//Contructor Function to create questions
function Question(question, choices, answer) {
this.question = question;
this.choices = choices;
this.answer = answer;
}

//Question Creations
questionsArray.push(new Question('Who is the Flash', ['Walter White', 'Johnny Cage', 'Barry Allen', 'Peter Parker'], 'Barry Allen'));
questionsArray.push(new Question('Who shot first?', ['Greedo did!', 'You know Han did!', 'Lee Harvey!'], 'You know Han did!'));
questionsArray.push(new Question('The Millenium Falcon made the Kessel Run in how many parsecs?', ['37', '2', '12', 'It never made the Kessel Run you fool!'], '12'));
questionsArray.push(new Question('Who is Scott Summers?', ['Cyclops', 'The Green Arrow', 'Deadpool', 'Ghost Rider'], 'Cyclops'));
questionsArray.push(new Question('Donatello preffered which weapon?', ['Katanas', 'Bo Staff', 'Sais', 'Nunchuks']));
questionsArray.push(new Question('Who lives long and prospers?', ["Rodians", 'Vulcans', 'Romulans','Republicans'], 'Vulcans'));
questionsArray.push(new Question('Who is Wade Wilson?', ['Deadpool', 'Deathstroke', 'Dr. Strange', 'Captain Marvel'], 'Deadpool'));
questionsArray.push(new Question('Who broke the Bat?', ['The Joker', 'Penguin', 'Bane', 'Deadshot'], 'Bane'));
questionsArray.push(new Question('Who turned Megatron into Galvatron?', ['Optimus Prime', 'Hot Rod', 'Starscream', 'Unicron'],'Unicron'));
questionsArray.push(new Question('Who is your daddy?', ['I am!','Obama', '...and what does he do?'], '...and what does he do?'));

function populateQuestion(index) {
$('.q_question').html(questionsArray[index]['question']);

for (var i = 0; i < 10; i++) {
$('.jumbotron').html('');
$('.btn' + (i + 1)).val(questionsArray[index]['choices'][i]).prop('checked', false);
$('.label' + (i + 1)).html(questionsArray[index]['choices'][i]);
}
}

populateQuestion(currentQuestion);

//This register the answer to each question
$('#submit').on('click', function() {
var answer = $('input[name="1"]:checked').val();
if (answer == questionsArray[i]['answer']) {
correctAnswers++;
$('.jumbotron').html(answer + "?

That's correct!  You have " + correctAnswers + " out of 10 correct!");
} else {
$('.jumbotron').html(answer + "?

Oh dear, that's so so wrong! You have " + correctAnswers + " out of 10 correct");
}
return false;
});

$('.continue').on('click', function() {
populateQuestion(++currentQuestion);
});

});< /code>
/*Title Style*/

body {
background-color: #347f5f;
}

.header {
text-align: center;
background-color: #296048;
border-radius: 3%;
box-shadow: 3px 3px 10px;
}

.q_title {
background-color: #37956d;
box-shadow: 3px 3px 10px;
width: 50%;
border-radius: 5%;
text-align: center;
}

button {
width: 100px;
height: 50px;
}

.jumbotron {
width: 200px;
height: 100px;
background-color: white;
}< /code>


Welcome to My Super Awesome Quiz!!
Ver.  1.1


 



 

 

 

 







Continue you on...if you dare!



Подробнее здесь: https://stackoverflow.com/questions/342 ... dio-button
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Jquery»