Hi, im new to javascript and i need to develop a test in javascript and html (90 questions and each question has 3 radio buttons for the 3 posible answers) , the html part is done, in the javascript part i need to get in 6 different variables the value of some radio buttons . depending of the question each question add its radio button value to a any of the 6 variables , so in my html code i grouped the question by names and each one has a different id, so the javascript can access them as an array. The problem is that when i use alert to show the results of 2 different questions, for example 2 and the other 2, the alert is showing me 2 2 instead of 4. Here is my code:
document.querySelector(‘.button’).addEventListener(‘click’, function(){
//var totalI
var totalI =0;
function pregunta1(totalI){
for (var i=0; i<document.form.pregunta1.length; i++) {
if (document.form.pregunta1[i].checked) {
totalI = document.form.pregunta1[i].value;
return totalI;
}
}
}
function pregunta4(totalI){
for (var i=0; i<document.form.pregunta4.length; i++) {
if (document.form.pregunta4[i].checked) {
totalI = document.form.pregunta4[i].value;
return totalI;
}
}
}
totalI = (pregunta1(totalI) + pregunta4(totalI));
alert(totalI);
//alert(totalR + ” ” + totalC + ” ” + totalI + ” ” + totalL + ” ” + totalB + ” ” + totalS);
});