Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write two functions. The first function is called readinput and takes no inputs.

ID: 3574147 • Letter: W

Question

Write two functions. The first function is called readinput and takes no inputs. This function should read in numbers from the user until the word "quit" is entered. As each number is read in, the running sum and running count should be updated by this function. The second function is called moan and also takes no inputs. This function should call readinputs() and then computes the average of all the numbers entered and writes the average to the HTML document. var count=0; var sum=0; function readinput() {function meant) {

Explanation / Answer

Note : Save programme as filename.html
<html>
<body>
<p id="demo"></p>
</body>
</html>
<script>
// varilble declared as global
var sum=0,count=0;
// vfunction degination for readInput
function readInput()
{

// loop to take input values until user enter quit
   while(1)
{
   var x = prompt("Enter Number or Enter quit", "");

   if(x=="quit")
   {
    break;
   }
   //calculate sum,count for number of integers entered
   sum=sum+parseInt(x);
    count++;
}


}
//function defination for mean
function mean()
{
readInput();   //calling readInput method
var mean =sum/count; //finding mean
//alert(sum);
document.getElementById("demo").innerHTML = "Number of inputs : "+count+"<br>Mean : "+mean; //set mean value to html page

}
mean(); //calling mean method
</script>

Output :

Number of inputs : 6
Mean : 3.5