I have a select list of salaries and I am attempting to find the sum of all array values greater than the value selected from the list. I am unable to get my code to output the sum.
salaries = [59360, 37012, 30301, 39738, 39169, 52832, 42132, 41220, 36901, 54497, 53108, 32553, 43023, 51505, 31499];
document.getElementById('go').onclick = function() {
var numberFilter = document.getElementById('filter').value;
total = 0;
for (index = 0; index < salaries.length; index++) {
if (salaries[index] > numberFilter) {
total = total + salaries[index];
document.getElementById('result').value = total;
};
};
};
<select id='filter' name=''>
<option value = '0'>0</option>
<option value = '30000'>30000</option>
<option value = '35000'>35000</option>
<option value = '40000'>40000</option>
<option value = '45000'>45000</option>
<option value = '50000'>50000</option>
<option value = '55000'>55000</option>
</select>
<button id='go' class=''>GO</button>
<input id='result' name='' value='' class=''>
<input id='count' name='' value='' class=''>
<script src='js/javascript 15.js'></script>
numbers
? – Ssswift Oct 27 '17 at 18:26numberFilter
variable anywhere in sight. – Mörre Oct 27 '17 at 18:28