I am currently facing an issue with a script that I have created to count array elements matching a user input. Strangely, all if statements in the script seem to be returning false.
I have verified that both the array element and the input value are strings, so I can't seem to pinpoint why this problem is occurring.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>
<input type="text" id="searchType">
</div>
<p id="count"></p>
<script type="text/javascript">
var bloodTypes = ["A+", "O-", "AB+", "O+", "AB+", "AB+", "O-", "AB+", "0+", "AB+"];
var n = 0;
for (var i = 0; i < bloodTypes.length; i++) {
if (bloodTypes[i] == document.getElementById("searchType").value){
n++;
}
}
document.getElementById("count").innerHTML = n;
</script>
</body>
</html>