Dear forum users, there is a test code (code below) which takes the values of a block consisting of <input type="radio"> with the same id. It checks which value is correct and if the item with value=1 selected, then it considers the question correctly answered. But I needed to make several answers. But so that if at least one of them is wrong, then the whole question is considered wrong. That is, if you need to choose 3 options, then only the answer was counted as correct, with these 3 options answered. Can you help implement JS check?
function count() { answer = 0; answerBlocksCount = document.form1.getElementsByTagName("p").length; questionsCount = document.form1.querySelectorAll('input[type=radio]').length + 1; var ball = 0; var good = ""; var bad = ""; var solv = 1; for (var i = 0; i < questionsCount; i++) { if (document.form1.elements[i].checked) { if (document.form1.elements[i].value != 0) { if (good != "") { good += ", " + solv; } else { good += "№ " + solv; } } else { if (bad != "") { bad += ", " + solv; } else { bad += "№ " + solv; } } solv++; } } for (var i = 0; i < questionsCount; i++) { if (document.form1.elements[i].checked) { answer += 1; } } if (answer < answerBlocksCount) { alert("Вы не ответили на все вопросы теста!"); } else { if (good == "") good = " нет :("; if (bad == "") bad = " нет =)"; var answer = "<span style=color:green>Решены правильно:</span> " + good + "<br>"; if (bad == "нет") { answer += "Неправильно: " + bad + "."; } else { answer += "<span style=color:red>Неправильно:</span>" + bad + ""; } if (navigator.userAgent.toLowerCase().indexOf("gecko") > 0) { div1 = document.getElementById('div1'); } div1.innerHTML = answer; div1.style.display = 'block'; var paragraphs = document.form1.getElementsByTagName("i").length; for (s = 0; s < paragraphs.length; s++) { if (document.form1.elements[s].checked) { paragraphs(s).style.fontWeight = 'bold'; if (document.form1.elements[s].value != 0) { paragraphs(s).style.color = 'green'; } else { paragraphs(s).style.color = 'red'; } } } } } <form name="form1" class="test"> <p>1. Вопрос 1 <br> <input type="radio" name="a" value="1"><i>Вариант 1</i> <br> <input type="radio" name="a" value="0"><i>Вариант 2</i> <br> <input type="radio" name="a" value="0"><i>Вариант 3</i> <br> <input type="radio" name="a" value="0"><i>Вариант 4</i> <br> <input type="radio" name="a" value="0"><i>Вариант 5</i> </p> <p>2. Вопрос 2 <br> <input type="radio" name="b" value="0"><i>Вариант 1</i> <br> <input type="radio" name="b" value="0"><i>Вариант 2</i> <br> <input type="radio" name="b" value="0"><i>Вариант 3</i> <br> <input type="radio" name="b" value="1"><i>Вариант 4</i> <br> <input type="radio" name="b" value="0"><i>Вариант 5</i> </p> <p>3. Вопрос 3 <br> <input type="radio" name="c" value="0"><i>Вариант 1</i> <br> <input type="radio" name="c" value="1"><i>Вариант 2</i> <br> <input type="radio" name="c" value="0"><i>Вариант 3</i> <br> <input type="radio" name="c" value="0"><i>Вариант 4</i> <br> <input type="radio" name="c" value="0"><i>Вариант 5</i> </p> <div border="1" id="div1" style="padding:9px 0 11px 10px;margin:9px 17px;border:1px solid green;display:none;"></div> <input type="button" value="Узнать результат" onclick="count();"> </form>