My code works but my math is off! How can I get my code to find the sum of odd and even numbers?
function getNum()
{
var div = document.getElementById("output");
div.innerHTML = "Numbers entered:<br>";
var score = 0;
var sum = 0;
var count = 0;
var average = 0;
var oddCount = 0;
var evenCount = 0;
var label = "";
var odd = 0;
var even = 0;
while (score != -999)
{
sum = sum + score;
count = count + 1; //or count++
score = parseInt(prompt("Enter an integer (or enter -999 to quit:"," "),10);
if(score % 2)
{
label = " is odd";
//even = even + score;
}
else
{
label = " is even";
//odd = odd + score;
}
div.innerHTML = div.innerHTML + score + label + "<br>";
//find odd score and even score
if ((score != -999) && ((score % 2) === 0))
{
evenCount++;
}
if ((score != -999) && ((score % 2) !== 0))
{
oddCount++;
}
}
count = count - 1; //dont count -999
sum = sum + oddCount;
average = sum/oddCount;
div.innerHTML = div.innerHTML + "You entered: " + oddCount + " odd numbers." + "<br>";
div.innerHTML = div.innerHTML + "The sum of these numbers is " + sum + ".<br>";
div.innerHTML = div.innerHTML + "The average of these numbers = " + sum + " / " + oddCount + " = " + average.toFixed(2) + ".<br><br>";
count = count - 1; //dont count -999
sum = sum + evenCount;
average = sum/evenCount;
div.innerHTML = div.innerHTML + "You entered: " + evenCount + " even numbers." + "<br>";
div.innerHTML = div.innerHTML + "The sum of these numbers is " + sum + ".<br>";
div.innerHTML = div.innerHTML + "The average of these numbers = " + sum + " / " + evenCount + " = " + average.toFixed(2) + ".<br>";
}// end of function