Question

In: Computer Science

Design and implement a JavaScript program to accomplish the following: 1. Iterate and accept N test...

Design and implement a JavaScript program to accomplish the following: 1. Iterate and accept N test scores and N student names (where 10 <= N <= 20). 2. Compute the sum and average of the scores (display these values). 3. Implement a function that determines the highest score (display this value). 4. Implement a function that determines the lowest score (display this value). 5. Implement a function that determines the letter grade of each score: 90-100 (A); 80 - 89 (b); 70 - 79 (C); 60 - 69 (D); 0 - 59 (F) 6. Display a table showing each student's name, score, and letter grade. 7. The highest and lowest scores should be highlighted with different colors. Complete the determineGrade function in the sample solution using if statements - not switch statement.

This is the 4th time im posting this since every answer im getting is not working

Solutions

Expert Solution


// #2 Finding sum of all scores
function sum(marks_array){
var sum = 0;
   for( var i = 0; i < marks_array.length; i++ ){
   sum += parseInt( marks_array[i], 10 );
   }

   var avg = sum/marks_array.length;
   //document.write( "The sum of all the elements is: " + sum);
return sum;
}


// #2 finding average of scores
function avg(marks_array){
   var sm = sum(marks_array);
   var avg = sm/marks_array.length;
   //document.write("Avg: "+avg);
   return avg;
}


// #3 finding highest score
function highest(marks_array){
var max = Number.NEGATIVE_INFINITY;
   for( var i = 0; i < marks_array.length; i++ ){
   if(max < parseInt(marks_array[i],10)){
   max = marks_array[i]
}
   }
//document.write(max);
return max;
}

// #4 finding lowest score
function lowest(marks_array){
var min = Number.POSITIVE_INFINITY;
   for( var i = 0; i < marks_array.length; i++ ){
   if(min > parseInt(marks_array[i],10)){
   min = marks_array[i]
}
   }
//document.write(min);
return min;
}


// #5 Displace letter grade as per the marks
function letterGrade(marks){
   marks = parseInt(marks);
   var grade;
   if(90<=marks){
       grade = 'A';
   }else if(80<=marks && marks<=89){
       grade = 'B';
   }else if(70<=marks && marks<=79){
       grade = 'C';
   }else if(60<=marks && marks<=69){
       grade = 'D';
   }else{
       grade = 'F';
   }
   //document.write(grade);
   return grade;
}

// # displaying grades in table formate
function createGradeTable(students, marks){
   var html = "<table><tr bgcolor='#AFAFA8'>";
   html += "<td><b>S.No.</b></td>";
   html += "<td><b>Name</b></td>";
   html += "<td><b>Marks</b></td>";
   html += "<td><b>Grade</b></td></tr>";
   for(var i=0; i< students.length; i++){
       if(highest(marks)==marks[i]){ // if marks is highest in the class background color is greenish
           html += "<tr bgcolor='#33FF9F'>"
       }else if(lowest(marks)==marks[i]){   // if marks is lowest in the class background color is reddish
           html += "<tr bgcolor='#FF5733'>"
       }else{                               // general background color is light yellow
           html += "<tr bgcolor='#FFFFEC'>"
       }
       html += "<td>"+(i+1)+"</td>";
       html += "<td color='red'>"+students[i]+"</td>";
       html += "<td>"+marks[i]+"</td>";
       html += "<td>"+letterGrade(marks[i])+"</td></tr>";
   }

   html += "</tr></table>";
   return html;
}


Related Solutions

I need to design and implement a JAVASCRIPT program that will allow us to determine the...
I need to design and implement a JAVASCRIPT program that will allow us to determine the length of time needed to pay off a credit card balance, as well as the total interest paid. The program must implement the following functions: displayWelcome This function should display the welcome message to the user explaining what the program does. calculateMinimumPayment This function calculates the minimum payment. It should take balance and minimum payment rate as arguments and return the minimum payment. So...
Bank Accounts in Java! Design and implement a Java program that does the following: 1) reads...
Bank Accounts in Java! Design and implement a Java program that does the following: 1) reads in the principle 2) reads in additional money deposited each year (treat this as a constant) 3) reads in years to grow, and 4) reads in interest rate And then finally prints out how much money they would have each year. See below for formatting. Enter the principle: XX Enter the annual addition: XX Enter the number of years to grow: XX Enter the...
Design and implement a C++ program that performs the following steps:Ask the user to enter a...
Design and implement a C++ program that performs the following steps:Ask the user to enter a positive integer number N; Your program may need to prompt the user to enter many times until it reads in a positive number;Let user to enter N (obtained in the previous step) floating point numbers, and count how many positive ones there are in the sequence and sum up these positive numbers; (Hint: negative numbers or 0 are ignored).Display result.You can and should use...
1. Design and implement a program that reads a series of integers from the user and...
1. Design and implement a program that reads a series of integers from the user and continually prints their average after every reading. The input stops when the user enters “stop” as the input value. Read each input value as a string, then check if it is “stop” or not. If the string is not “stop”, then, attempt to convert it to an integer using the Integer.parseInt method. If this process throws a NumberFormatException, meaning that the input is not...
Write a program to perform the following two tasks: 1. The program will accept a string...
Write a program to perform the following two tasks: 1. The program will accept a string as input in which all of the words are run together, but the first character of each word is uppercase. Convert the string to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string "StopAndSmellTheRose" would be converted to "Stop and smell the rose". Display the result string. 2. Then...
Write a program to perform the following two tasks: 1. The program will accept a string...
Write a program to perform the following two tasks: 1. The program will accept a string as input in which all of the words are run together, but the first character of each word is uppercase. Convert the string to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string "StopAndSmellTheRose" would be converted to "Stop and smell the rose". Display the result string. 2. Then...
1) Design an implement a program that created and exception class called StringTooLongException, designed to be...
1) Design an implement a program that created and exception class called StringTooLongException, designed to be thrown when a string is discovered that has too many characters in it. Create a driver that reads in strings from the user until the user enters DONE. If a string that has more then 5 characters is entered, throw the exception. Allow the thrown exception to terminate the program 2) Create a class called TestScore that has a constructor that accepts an array...
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...
For this program you will implement the following utility functions to test mastery of C strings....
For this program you will implement the following utility functions to test mastery of C strings. *******you MUST use these these function***** void removeBlanks(char *src, char *dest); void replaceChar(char *src, char oldChar, char newChar); char *flipCase(const char *src); Please read the description of these functions carefully. In the removeBlanks function you will implement a routine that takes a string in as src and outputs the same string into dest but removing any blank space character encountered. For example, if the...
Design and implement a Java program that creates a GUI that will allow a customer to...
Design and implement a Java program that creates a GUI that will allow a customer to order pizza and other items from a Pizza Paarlor. The customer should be able to order a variety of items which are listed below. The GUI should allow the customer (viaJavaFX UI Controls - text areas, buttons, checkbox, radio button, etc.) to input the following information: Name of the customer First Name Last Name Phone number of the customer Type of food being order...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT