Question

In: Computer Science

Write a JavaScript program that computes the average of a collection of numbers and then outputs...

Write a JavaScript program that computes the average of a collection of numbers and then outputs the total number of values that are greater than the average.

An A grade is any score that is at least 20% greater than the average. The B grade is any score that is not an A, but is at least 10% greater than the average. An F grade is any score that is at least 20% less than the average. The D grade is any score that is not an F, but is at least 10% less than the average. Any scores that are within 10% of the average (either less than or greater than) are C's.

Solutions

Expert Solution

var arry = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

var sum = 0;

for( var i = 0; i < arry.length; i++ ){

sum = sum + arry[i]; //computing the sum of numbers

}

//computing the average

var avg = sum/arry.length;

var count = 0;

for( var i = 0; i < arry.length; i++){

if( arry[i] > avg)

count = count + 1; //number of scroes greater than average

}

document.write( "The number of values greater than average are " + count);

document.write("<br>")

//computing the grades for the respective scores

for( var i = 0; i < arry.length; i++){

document.write( "Score "+ arry[i] +" has ");

if( arry[i] > (avg * 1.2) ){

document.write("Grade A");

} else if(arry[i] > (avg * 1.1)){

document.write("Grade B");

} else if(arry[i] <= (avg * 0.8)){

document.write("Grade F");

} else if(arry[i] <= (avg * 0.9)){

document.write("Grade D");

}else{

document.write("Grade C");

}

document.write("<br>")

}

Screenshot of the program:

Output of the program:

Hoping that the solution helps !!


Related Solutions

Write a defining table and a JavaScript program that computes and outputs the rate of change...
Write a defining table and a JavaScript program that computes and outputs the rate of change of a price. The program must allow the user to enter a previous price and a current price. The formula for the rate of change is rateOfChange =  currPrice - prevPrice prevPrice Your program should allow a user to enter real numbers such as 7.54. If you wish, you may use the following HTML code in your program. <!DOCTYPE HTML> <html lang="en-us"> <head> <meta charset="utf-8">...
Write a program that computes and prints the average of numbers in a text file. I...
Write a program that computes and prints the average of numbers in a text file. I created a text file integers.txt that has the numbers 5,4,3,2,1. I need to define the average function Define the main function which will include the following things 1. prompt user for input of text file name 2. open and read input file, can be done before or inside high order functions 3. use two high order functions 4.calculate and display averages and original ist...
Write a defining table and a computer program that computes and outputs the volume of a...
Write a defining table and a computer program that computes and outputs the volume of a torus with inner radius a and outer radius b. A doughnut is an example of a torus. Your program must read the inner radius and outer radius from two text fields and display the volume in a div. The formula for the volume of a torus is v =  π2(a + b)(a - b)2 4 where v is the volume, π is the constant pi,...
Write the programs in JavaScript: Write a program that reads a text file and outputs the...
Write the programs in JavaScript: Write a program that reads a text file and outputs the text file with line numbers at the beginning of each line.
Write a program that takes, as input, five numbers and outputs the mean (average) and standard...
Write a program that takes, as input, five numbers and outputs the mean (average) and standard deviation of the numbers. If the numbers are x₁, x₂, x₃, x₄, and x₅, then the mean is: x = (x₁+ x₂+ x₃+ x₄+x₅)/5 and the standard deviation is: s = √(((x₁-x)²+(x₂-x)²+(x₃-x)²+(x₄-x)²+(x₅-x)²)/5) Your program must contain at least the following functions: a function that calculates and returns the mean and a function that calculates the standard deviation. Format your output with setprecision(2) to ensure...
Write a program in C++ that computes the sum of odd numbers between 1 and 117....
Write a program in C++ that computes the sum of odd numbers between 1 and 117. Execute the program and submit a screen capture of the program and its results.
Write a C++ program that inputs a sequence of integers into a vector, computes the average,...
Write a C++ program that inputs a sequence of integers into a vector, computes the average, and then outputs the # of input values, the average, and the values themselves. There are 0 or more inputs values, followed by a negative value as the sentinel; the negative value is not stored and not counted. The following sample input: 10 20 0 99 -1 would produce the following output: N: 4 Avg: 32.25 10 20 0 99 The main program has...
Write a C++ program that inputs a sequence of integers into a vector, computes the average,...
Write a C++ program that inputs a sequence of integers into a vector, computes the average, and then outputs the # of input values, the average, and the values themselves. There are 0 or more inputs values, followed by a negative value as the sentinel; the negative value is not stored and not counted. The following sample input: 10 20 0 99 -1 would produce the following output: N: 4 Avg: 32.25 10 20 0 99 The main program has...
Using Java Write a program that reads a file of numbers of type int and outputs...
Using Java Write a program that reads a file of numbers of type int and outputs all of those numbers to another file, but without any duplicate numbers. You should assume that the input file is sorted from smallest to largest with one number on each line. After the program is run, the output file should contain all numbers that are in the original file, but no number should appear more than once. The numbers in the output file should...
Write a Python program that computes certain values such as sum, product, max, min and average...
Write a Python program that computes certain values such as sum, product, max, min and average of any 5 given numbers along with the following requirements. Define a function that takes 5 numbers, calculates and returns the sum of the numbers. Define a function that takes 5 numbers, calculates and returns the product of the numbers. Define a function that takes 5 numbers, calculates and returns the average of the numbers. Must use the function you defined earlier to find...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT