hi i'm having a difficult time with the challenge assignment. I'm trying to remove in the script the second and third prompts, and replace them with the first prompt that starts when the button is clicked. Programming Challenge On Your Own: 5.7 Description: Prompts user to enter as many integers as desired. The program will keep track of how many are odd and how many are even. At the end the sum and averages of all odds and evens are displayed.
<!--------- hi i'm having a difficult time with the challenge assignment. I'm trying to remove in the script the second and third prompts, and replace them with the first prompt that starts when the button is clicked.
Programming Challenge
On Your Own: 5.7
Description: Prompts user to enter as many integers as desired. The
will keep track of how many are odd and how many are even.
At the end the sum and averages of all odds and evens are displayed.
------------>
<html>
<head>
<title>Odds and Evens</title>
</head>
<body>
<div style="width: 700px; margin: auto; margin-top: 100px; border: 1px solid black; padding: 5px; background-color: #E7E7E7;">
<p style="font-weight: bold;">Lab 4b</p>
<p>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.</p>
<p>Begin the process by clicking on the 'BEGIN' button below.</p>
<br /><hr /><br />
<input type="button" onclick="oddsEvens()" value="< < BEGIN > >" />
<div id="odd_result"> </div>
<div id="even_result"> </div>
</div>
<script>
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("<br/>All even numbers in the array are: " + arrayEven);
document.write("<br/> The sum of all even numbers is: " + sumEven + " and average of the even numbers is: " + avgE);
document.write("<br/>");
document.write("<br/>All odd numbers in the array are: " + arrayOdd);
document.write("<br/> The sum of all odd numbers is: " + sumOdd + " and the average of the odd numbers is " + avgO);
</script>
</body>
</html>
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images