2
I’m doing some Javascript exercises and I came across this problem, in counting boolean values. I converted the Nodelist into an Array to try to count the values by the method for(), filter() switch(), however, I only get the return of the value 0, and I would like to return the amount of true
 and false .
<body>
    <h1>Height and Sex</h1>
    <p>Type the height and sex: </p>
    <div>
        <input type="text" name="height" class="height" placeholder="Centimeter" minlength="3" maxlength="3">
        <input type="radio" name="op1" value="Man" class="sex"><label>Man</label>
        <input type="radio" name="op1" value="Woman" class="sex"><label>Woman</label>
        <br>
        <input type="text" name="height" class="height" placeholder="Centimeter" minlength="3" maxlength="3">
        <input type="radio" name="op2" value="Man" class="sex"><label>Man</label>
        <input type="radio" name="op2" value="Woman" class="sex"><label>Woman</label>
        <br>
        <input type="text" name="height" class="height" placeholder="Centimeter" minlength="3" maxlength="3">
        <input type="radio" name="op3" value="Man" class="sex"><label>Man</label>
        <input type="radio" name="op3" value="Woman" class="sex"><label>Woman</label>
        <br>
        <input type="text" name="height" class="height" placeholder="Centimeter" minlength="3" maxlength="3">
        <input type="radio" name="op4" value="Man" class="sex"><label>Man</label>
        <input type="radio" name="op4" value="Woman" class="sex"><label>Woman</label>
        <br>
        <input type="text" name="height" class="height" placeholder="Centimeter" minlength="3" maxlength="3">
        <input type="radio" name="op5" value="Man" class="sex"><label>Man</label>
        <input type="radio" name="op5" value="Woman" class="sex"><label>Woman</label>
    </div>
    <br>
    <button id="btn">Submit!</button>
    var sx = document.querySelectorAll(".sex");
    let sx_h = [sx[0].checked, sx[2].checked, sx[4].checked, sx[6].checked, sx[8].checked];
    let sx_m = [sx[1].checked, sx[3].checked, sx[5].checked, sx[7].checked, sx[9].checked];
    for(i = 0; sx_h.values == true; i++){
        return i
    }
    console.log(i)