Odds and Evens









Lab 4b




This program will keep track of odd and even integers entered by the user. At the end, the sum and average of the odds and the evens will be displayed.




Begin the process by clicking on the 'BEGIN' button below.

























 

    function oddsEvens()
            {
                do
                {
                    var userEntry = prompt('Enter any integer. Enter the word \"quit" and i\'ll leave you alone.');
                    console.log(userEntry);
                }while(userEntry != "quit");
            }
 

/*
        //Variable and array declaration

var arrayNum = [];
var arrayEven = []; 
var arrayOdd = []; 
var i; 
var NUM_INPUTS;
var sumOdd = 0.0;
var sumEven = 0.0; 
var avgO = 0.0;
var avgE = 0.0;

NUM_INPUTS = parseInt(prompt("Enter the number of inputs you need: "));
for (i = 0; i < num_inputs;="" i++)="">
  arrayNum.push(parseFloat(prompt("Enter the numbers: " + (i + 1))));
  if ((arrayNum[i] % 2) === 1) {
    arrayOdd.push(arrayNum[i]);
    sumOdd += arrayNum[i];
  }
  else {
    arrayEven.push(arrayNum[i]);
    sumEven += arrayNum[i];

  }
}
avgO = sumOdd / arrayOdd.length;
avgE = sumEven / arrayEven.length;
//Output results
document.write("All numbers in the array are: " + arrayNum);

document.write("
All even numbers in the array are: " + arrayEven);
document.write("
The sum of all even numbers is: " + sumEven + " and average of the even numbers is: " + avgE);

document.write("
");
document.write("
All odd numbers in the array are: " + arrayOdd);
document.write("
The sum of all odd numbers is: " + sumOdd + " and the average of the odd numbers is " + avgO);






Jun 03, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here