Hello everyone i have been developing a quiz. this quiz has 5 questions that display one after another. i would like to make it so, that after the 5th question it displays the answers. I have been using this piece of javascript to write the answers after the first click :
const button = document.querySelector("#button")
button.addEventListener("click", e => {
const rb = document.querySelector('input[name="_exam_"]:checked');
document.write(rb.value);
});
this makes it so that it writes the scores of the first question on screen. but i cant find out how to make it so that this only happens after the last question and that it shows all 5 answers.
so my question is ; how can i store the selected answers from the radio objects?
and how can i show these answers at the end?
const button = document.querySelector("#button")
button.addEventListener("click", e => {
const rb = document.querySelector('input[name="_exam_"]:checked');
document.write(rb.value);
});
$(document).ready(function () {
//hide all questions
$('.questionForm').hide();
$('#results').hide();
//show first question
$('#q1').show();
$('#q1 #button').click(function () {
$('.questionForm').hide();
$('#q2').show();
return false;
});
$('#q2 #button').click(function () {
$('.questionForm').hide();
$('#q3').show();
return false;
});
$('#q3 #button').click(function () {
$('.questionForm').hide();
$('#q4').show();
return false;
});
$('#q4 #button').click(function () {
$('.questionForm').hide();
$('#q5').show();
return false;
});
$('#q5 #button').click(function () {
$('.questionForm').hide();
$('#results').show();
return false;
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="STYLE.CSS">
<title>Document</title>
</head>
<body>
<form class="questionForm" id="q1" data-question="1">
<div>
<p>Question 1</p>
<p><input type="radio" name="_exam_" value="a">A. Rustgeving</p>
<p><input type="radio" name="_exam_" value="b">B. Zingeving</p>
<p><input type="radio" name="_exam_" value="c">C. Duurzaamheid</p>
<p><input type="radio" name="_exam_" value="d">D. Verzuiling</p>
<p><input type="radio" name="_exam_" value="e">E. Zorgzaamheid</p>
</div>
<input id="button" type="button" value="Volgende">
</form>
<form class="questionForm" id="q2" data-question="2">
<div>
<p>Question 2</p>
<p><input type="radio" name="_exam_" value="a">A. Rustgeving</p>
<p><input type="radio" name="_exam_" value="b">B. Zingeving</p>
<p><input type="radio" name="_exam_" value="c">C. Duurzaamheid</p>
<p><input type="radio" name="_exam_" value="d">D. Verzuiling</p>
<p><input type="radio" name="_exam_" value="e">E. Zorgzaamheid</p>
</div>
<input id="button" type="button" value="Volgende">
</form>
<form class="questionForm" id="q3" data-question="3">
<div>
<p>Question 3</p>
<p><input type="radio" name="_exam_" value="a">A. Rustgeving</p>
<p><input type="radio" name="_exam_" value="b">B. Zingeving</p>
<p><input type="radio" name="_exam_" value="c">C. Duurzaamheid</p>
<p><input type="radio" name="_exam_" value="d">D. Verzuiling</p>
<p><input type="radio" name="_exam_" value="e">E. Zorgzaamheid</p>
</div>
<input id="button" type="button" value="Volgende">
</form>
<form class="questionForm" id="q4" data-question="4">
<div>
<p>Question 4</p>
<p><input type="radio" name="_exam_" value="a">A. Rustgeving</p>
<p><input type="radio" name="_exam_" value="b">B. Zingeving</p>
<p><input type="radio" name="_exam_" value="c">C. Duurzaamheid</p>
<p><input type="radio" name="_exam_" value="d">D. Verzuiling</p>
<p><input type="radio" name="_exam_" value="e">E. Zorgzaamheid</p>
</div>
<input id="button" type="button" value="Volgende">
</form>
<form class="questionForm" id="q5" data-question="5">
<div>
<p>Question 5</p>
<p><input type="radio" name="_exam_" value="a">A. Rustgeving</p>
<p><input type="radio" name="_exam_" value="b">B. Zingeving</p>
<p><input type="radio" name="_exam_" value="c">C. Duurzaamheid</p>
<p><input type="radio" name="_exam_" value="d">D. Verzuiling</p>
<p><input type="radio" name="_exam_" value="e">E. Zorgzaamheid</p>
</div>
<input id="button" type="button" value="Volgende">
</form>
<form class="questionForm" id="results" data-question="6">
<p> here are your results</p>
</form>
</div>
<script src="jquery.js"></script>
<script src="quiz.js"></script>
</body>
</html>