Need Help Debugging JavaScript | XM Community
Skip to main content
Can anyone figure out the coding error that I have in this if/then statement?



if (gender1 ==='Feminino') {

if(age1 <= 15){ f_kids++;} else if (age1>15 && age1 < 60 ){f_ adults++; } else if (age1 > 59 ){f_seniors++;} else{empty++;}

} else {

if(age1 <= 15){ m_kids++;} else if (age1>15 && age1 < 60 ){m_ adults++; } else if (age1 > 59 ){m_seniors++;} else{empty++;}

}

I would like to use this in a Qualtrics survey to calculate the total number of female "Feminino" adults, kids and seniors from a previous question where the respondents enter in the name, age and gender of the individuals in the household. I eventually want to use the code to make these calculations for up to 15 household members - just testing the code for the first household member here.



I first set the variables to zero (before the code above)

let m_adults = 0;

let f_adults = 0;

let f_kids = 0;

let f_seniors = 0;

let m_kids = 0;

let m_seniors = 0;



and before that I read in the responses:

let age1= parseInt("${q://QID8%232/ChoiceTextEntryValue/1/1}");

let age2= parseInt("${q://QID8%232/ChoiceTextEntryValue/2/1}");

let age3= parseInt("${q://QID8%232/ChoiceTextEntryValue/3/1}");

let age4= parseInt("${q://QID8%232/ChoiceTextEntryValue/4/1}");

let age5= parseInt("${q://QID8%232/ChoiceTextEntryValue/5/1}");

let age6= parseInt("${q://QID8%232/ChoiceTextEntryValue/6/1}");

let age7= parseInt("${q://QID8%232/ChoiceTextEntryValue/7/1}");

let age8= parseInt("${q://QID8%232/ChoiceTextEntryValue/8/1}");

let age9= parseInt("${q://QID8%232/ChoiceTextEntryValue/9/1}");

let age10= parseInt("${q://QID8%232/ChoiceTextEntryValue/10/1}");

let age11= parseInt("${q://QID8%232/ChoiceTextEntryValue/11/1}");

let age12= parseInt("${q://QID8%232/ChoiceTextEntryValue/12/1}");

let age13= parseInt("${q://QID8%232/ChoiceTextEntryValue/13/1}");

let age14= parseInt("${q://QID8%232/ChoiceTextEntryValue/14/1}");

let age15= parseInt("${q://QID8%232/ChoiceTextEntryValue/15/1}");



//reading in gender

let gender1= ("${q://QID8%233/ChoiceGroup/SelectedAnswers/1}");
Hello @jill_caviglia_harris ,



There is a space at `f_ adults++; ` and `m_ adults++;`
Thank you! that did it. I now have the code running for up to 15 household member. Much thanks!

Leave a Reply