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...
Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to...
Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to display the current day and time. b) Write a JavaScript program to print the contents of the current window.   c) Write a JavaScript program where the program takes a random integer between 1 to 10 d) Write a JavaScript program to calculate multiplication and division of two numbers (input from the user). e)Write a JavaScript program to create a new string from a given...
Write a JavaScript program with a function named fives that reads two numbers from two text...
Write a JavaScript program with a function named fives that reads two numbers from two text fields and then outputs to a div "True" if both of the numbers are greater than 5 or if their sum is greater than 20. Otherwise your function should output "False" to the div. If you wish, you may use the following HTML code to begin your program.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT