Stack Exchange
Running total average based on Radio button selection
I'm trying to get a running total average (in real time displayed in my span) based on users radio button selection but I'm not sure how to accomplish this in javascript. 
See what I have so far:
<form>
    <p>Question here</p>
    <input type="radio" class="check" name="choose" onchange="getAverage()" value=1>never
    <input type="radio" class="check" name="choose" onchange="getAverage()" value=2>sometimes
    <input type="radio" class="check" name="choose" onchange="getAverage()" value=3>regularly
    <input type="radio" class="check" name="choose" onchange="getAverage()" value=4>always
    <br>
</form>
<form>
    <p>Question here</p>
    <input type="radio" class="check" name="choose" onchange="getAverage()"  value=1>never
    <input type="radio" class="check" name="choose" onchange="getAverage()" value=2>sometimes
    <input type="radio" class="check" name="choose" onchange="getAverage()" value=3>regularly
    <input type="radio" class="check" name="choose" onchange="getAverage()" value=4>always
    <br>
</form>
<form>
    <p>Question here</p>
    <input type="radio" class="check" name="choose" onchange="getAverage()" value=1>never
    <input type="radio" class="check" name="choose" onchange="getAverage()" value=2>sometimes
    <input type="radio" class="check" name="choose" onchange="getAverage()" value=3>regularly
    <input type="radio" class="check" name="choose" onchange="getAverage()" value=4>always
    <br>
</form>

<br>
<div>Your average score is: <span id="score"></span></div>

<br>
<br>
<script>
    function getAverage() {
        var i;
        var total = 0;
        var value = document.querySelector('input[name="choose"]:checked').value;
        var count = document.querySelectorAll(".check:checked").length;

    }
</script>



Hint: Loop over all of the nodes and add their values to the total.

What do you mean by average score?

It's a running average score whenever user selects a radio button. I added the following code to your code: var count = document.querySelectorAll(".check:checked").length; var totalAverage = average / count; document.getElementById("score").innerText = Math.round( totalAverage



var btns = document.querySelectorAll('input[name="choose"]');
btns.forEach( function( btn) {
    btn.onclick = function () {            
        var average = 0;
        btns.forEach( function( btn ) {
            average = btn.checked ? (average + parseInt(btn.value)): average;                
        });
        document.getElementById("score").innerText = average;
    }
}); 
<form>
    <p>Question here</p>
    <input type="radio" class="check" name="choose" value=1>never
    <input type="radio" class="check" name="choose" value=2>sometimes
    <input type="radio" class="check" name="choose" value=3>regularly
    <input type="radio" class="check" name="choose" value=4>always
    <br>
</form>
<form>
    <p>Question here</p>
    <input type="radio" class="check" name="choose" value=1>never
    <input type="radio" class="check" name="choose" value=2>sometimes
    <input type="radio" class="check" name="choose" value=3>regularly
    <input type="radio" class="check" name="choose" value=4>always
    <br>
</form>
<form>
    <p>Question here</p>
    <input type="radio" class="check" name="choose" value=1>never
    <input type="radio" class="check" name="choose" value=2>sometimes
    <input type="radio" class="check" name="choose" value=3>regularly
    <input type="radio" class="check" name="choose" value=4>always
    <br>
</form>

<br>
<div>Your average score is: <span id="score"></span></div>

<br>
<br>




Thank you Murali! I added the following code to get the average.  var count = document.querySelectorAll(".check:checked").length;
var totalAverage = average / count;
document.getElementById("score").innerText = Math.round(
totalAverage

I'm assuming you want to update the average whenever the user clicks a button.
<form>
    <p>Question here</p>
    <input type="radio" class="check" name="choose" onclick="updateAverage(this)" value=1>never
    <input type="radio" class="check" name="choose" onclick="updateAverage(this)" value=2>sometimes
    <input type="radio" class="check" name="choose" onclick="updateAverage(this)" value=3>regularly
    <input type="radio" class="check" name="choose" onclick="updateAverage(this)" value=4>always
    <br>
</form>
<form>
    <p>Question here</p>
    <input type="radio" class="check" name="choose" onclick="updateAverage(this)"  value=1>never
    <input type="radio" class="check" name="choose" onclick="updateAverage(this)" value=2>sometimes
    <input type="radio" class="check" name="choose" onclick="updateAverage(this)" value=3>regularly
    <input type="radio" class="check" name="choose" onclick="updateAverage(this)" value=4>always
    <br>
</form>
<form>
    <p>Question here</p>
    <input type="radio" class="check" name="choose" onclick="updateAverage(this)" value=1>never
    <input type="radio" class="check" name="choose" onclick="updateAverage(this)" value=2>sometimes
    <input type="radio" class="check" name="choose" onclick="updateAverage(this)" value=3>regularly
    <input type="radio" class="check" name="choose" onclick="updateAverage(this)" value=4>always
    <br>
</form>

<br>
<div>Your average score is: <span id="score"></span></div>

<br>
<br>
<script>
    function averageTracker(display) {
        let counter = 0;
        let total = 0;
        return function(radioButton) {
            counter += 1;
            total += parseInt(radioButton.value);
            display.innerHTML = (total * 1.0) / counter;
        }
    }
    const updateAverage = averageTracker(document.getElementById("score"));
</script>


Thanks to your responses, I solved the problem. Here's the final Javascript code.
      function getAverage() {
        var btns = document.querySelectorAll('input[name="choose"]');
        btns.forEach(function(btn) {
          btn.onclick = function() {
            var average = 0;
            btns.forEach(function(btn) {
              average = btn.checked ? average + parseInt(btn.value) : average;
            });
            var count = document.querySelectorAll(".check:checked").length;
            var totalAverage = average / count;
            document.getElementById("score").innerText = Math.round(
              totalAverage
            );
            var answer = document.getElementById("score").innerHTML;
          };
        });
      }

