js__exam_questions();
function js__exam_questions() {
$('.js__sum_score_btn').on('click', function(event) {
event.preventDefault();
var num = 0;
if ($('.js__checked_task input').is(':checked')) {
num ++;
} else {
return false;
}
$('.js__checked_task');
return $('.js__qustions_result').html( num || 'null');
});
}
.d-inline {
display: inline-block;
}
.fz33 {
font-size: 33px;
}
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"> </script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<section id="questions">
<div class="questions__bg">
<div class="container">
<div class="row">
<!-- head -->
<div class="col-md-8">
<div class="control-group">
<h1>Questions:</h1>
<button type="button" class="js__sum_score_btn btn btn-default mb50">SUMMARY</button>
</div>
</div>
<div class="col-md-4">
<div class="control-group">
<h1 class="mr10 d-inline">Score:</h1><span class="js__qustions_result fz33">0</span>
</div>
</div>
<!-- task-1 -->
<div class="col-md-6 pb50 js__checked_task">
<div id="myquestions-1">
<h4 class="quest__h4">
<strong>Question</strong>: Lorem ipsum dolor sit amet, consectetur adipisicing.</h4>
<label class="radio-inline">
<input type="radio" name="questions_stage_1">Option 1
</label>
<label class="radio-inline">
<input type="radio" name="questions_stage_1">Option 2
</label>
<label class="radio-inline">
<input type="radio" name="questions_stage_1">Option 3
</label>
</div>
</div>
<!-- task-2 -->
<div class="col-md-6 pb50 js__checked_task">
<div id="myquestions-2">
<h4 class="quest__h4">
<strong>Question</strong>: Lorem ipsum dolor sit amet, consectetur adipisicing.</h4>
<label class="radio-inline">
<input type="radio" name="questions_stage_2">Option 1
</label>
<label class="radio-inline">
<input type="radio" name="questions_stage_2">Option 2
</label>
<label class="radio-inline">
<input type="radio" name="questions_stage_2">Option 3
</label>
</div>
</div>
<!-- task-3 -->
<div class="col-md-6 pb50 js__checked_task">
<div id="myquestions-3">
<h4 class="quest__h4">
<strong>Question</strong>: Lorem ipsum dolor sit amet, consectetur adipisicing.</h4>
<label class="radio-inline">
<input type="radio" name="questions_stage_3">Option 1
</label>
<label class="radio-inline">
<input type="radio" name="questions_stage_3">Option 2
</label>
<label class="radio-inline">
<input type="radio" name="questions_stage_3">Option 3
</label>
</div>
</div>
<!-- task-4 -->
<div class="col-md-6 pb50 js__checked_task">
<div id="myquestions-4">
<h4 class="quest__h4">
<strong>Question</strong>: Lorem ipsum dolor sit amet, consectetur adipisicing.</h4>
<label class="radio-inline">
<input type="radio" name="questions_stage_4">Option 1
</label>
<label class="radio-inline">
<input type="radio" name="questions_stage_4">Option 2
</label>
<label class="radio-inline">
<input type="radio" name="questions_stage_4">Option 3
</label>
</div>
</div>
</div>
</div>
</div>
</section>
Hello everyone, I'm trying to write a mini-test with scoring. I know that I need to use '.each', but for the time being I do not quite understand how to use it correctly, that would count each answer separately. Thank you.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.