Im trying to get a function to count the number of times a number appears in an array based on a selection from a dropdown.
If I do it direct with favouriteCar(3); I get a value of 2 in the console.
However if I select from the drop down, nothing happens.
<label for="cars">Choose a car to see how many people like it:</label>
<select name="cars" id="cars" onchange="favouriteCar(this.value);">
<option value="0">Please select a car...</option>
<option value="1">Audi</option>
<option value="2">VW</option>
<option value="3">BMW</option>
<option value="4">MG</option>
<option value="5">Suzuki</option>
</select>
<script>
const carlikes = [2, 4, 1, 4, 1, 5, 3, 3, 1, 4, 1];
function favouriteCar(value) {
var count = 0;
carlikes.forEach((v) => (v === value && count++));
return count;
console.log(count);
}
</script>