Question

In: Computer Science

JAVASCRIPT: Please create an array of student names and another array of student grades. - Create...

JAVASCRIPT:

Please create an array of student names and another array of student grades.
- Create a function that can put a name and a grade to the arrays.
- Keep Read student name and grade until student name is “???”. And save the reading by using a function
- Create another function to show all the grade in that object.
- Create the third function that can display the maximum grade and the student’s name.
- Create a sorting function that can sort the arrays based on the student’s grade.
- Display all the grades and names sorted by the grade.

Please modify the JavaScript code (HTML) below to meet the requirements, and submit it. Also submit a screenshot of the output.

<html>
<body>
<script>
//store student name in student array and the grade in grade array
function spush(slist, name, sgrade, grade){
slist.push(name);//student list
   sgrade.push(grade);//grade list
}
//show all the student names and their grades
function showlist(slist, sgrade){
var i;
for (i = 0; i < slist.length; i++){
document.writeln(slist[i] +" "+sgrade[i]+ "<br>");
}
}
function findmax(sgrade){
var i;
   var max;
   var maxid;
   max = sgrade[0];
   maxid = 0;
  
   for(i=1;i<sgrade.length; i++){
   if(max < sgrade[i]){
   max = sgrade[i];
       maxid = i;
   }}
  
return maxid;//using index number
   }
var stdlist = [];
var sgrade =[];
var mid;
//instead of following, please use prompt for input
spush(stdlist, "John", sgrade, 90);
spush(stdlist, "Tom", sgrade, 95);
spush(stdlist, "Mary", sgrade, 97);
showlist(stdlist, sgrade);
mid = findmax(sgrade);//max grade index number
  
document.writeln("The maximum grade: "+stdlist[mid]+" "+sgrade[mid]);
</script>
</body>
</html>

Solutions

Expert Solution

<html>
<body>
<script>
//store student name in student array and the grade in grade array
function spush(slist, name, sgrade, grade) {
  slist.push(name);//student list
  sgrade.push(grade);//grade list
}

//show all the student names and their grades
function showlist(slist, sgrade) {
  var i;
  for (i = 0; i < slist.length; i++) {
    document.writeln(slist[i] +" "+sgrade[i]+ "<br>");
  }
}

function findMaxIndex(sgrade){
  var i;
  var max;
  var maxid;
  max = sgrade[0];
  maxid = 0;

  for(i=1;i<sgrade.length; i++){
    if(max < sgrade[i]){
      max = sgrade[i];
      maxid = i;
    }
  }
  
  return maxid;//using index number
}

function swap(arr, i, j){
    var temp = arr[i];
    arr[i] = arr[j];
    arr[j] = temp;
}

function sortData(stdlist, sgrade) {
    var len = stdlist.length
    for (i=0; i < len; i++){
        for (j=0, stop=len-i; j < stop; j++){
            if (sgrade[j] > sgrade[j+1]){
                swap(sgrade, j, j+1);
                swap(stdlist, j, j+1);
            }
        }
    }
}

var stdlist = Array();
var sgrade = Array();
var name
while(name != '???') {
  name = prompt('Enter name of student');
  if(name == '???') {
    break;
  }
  var grade = parseFloat(prompt('Enter grades: '));
  spush(stdlist, name, sgrade, grade);
}

showlist(stdlist, sgrade)
var index = findMaxIndex(sgrade)
document.writeln("The maximum grade: "+stdlist[index]+" "+sgrade[index]);

sortData(stdlist, sgrade)
showlist(stdlist, sgrade)

</script>
</body>
</html>
**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.


Related Solutions

JAVASCRIPT: - Please create an object (grade) with 10 names and 10 grades. - Create a...
JAVASCRIPT: - Please create an object (grade) with 10 names and 10 grades. - Create a method (inputGrade) that can put a name and a grade to the grade object. - Create another method (showAlltheGrades) to show all the grade in that object. - Create the third method (MaxGrade) that can display the maximum grade and the student name. - Using “prompt” and inputGrade method input 10 student names and their grades. - Display all the grades and names by...
JAVASCRIPT: - Please create an object (grade) with 10 names and 10 grades. - Create a...
JAVASCRIPT: - Please create an object (grade) with 10 names and 10 grades. - Create a method (inputGrade) that can put a name and a grade to the grade object. - Create another method (showAlltheGrades) to show all the grade in that object. - Create the third method (MaxGrade) that can display the maximum grade and the student name. - Using “prompt” and inputGrade method input 10 student names and their grades. - Display all the grades and names by...
JavaScript - Create a class using "names" as the identifier. Create a constructor. The constructor must...
JavaScript - Create a class using "names" as the identifier. Create a constructor. The constructor must have elements as follow: first ( value passed will be String ) last ( value passed will be String ) age ( value passed will be Numeric ) The constructor will assign the values for the three elements and should use the "this" keyword Create a function, using "printObject" as the identifier printObject: This function will have three input parameters: allNames , sortType, message...
Create an array list (names) that will hold the names of several hall of fame soccer...
Create an array list (names) that will hold the names of several hall of fame soccer players. 2. Place your name on the screen as the master recorder:              “Master Hall of Fame Recorder: John Paul Jones” 3. Ask the user how many names they would like to record. (input 5 when the program runs) 4. Create a loop that will ask for the “Hall of fame member #1: “, etc Add in the following names: Pele Rooney Maradona Messi...
JAVASCRIPT Create an array of 5 objects named "movies" Each object in the movies array, should...
JAVASCRIPT Create an array of 5 objects named "movies" Each object in the movies array, should have the following properties: Movie Name Director Name Year Released WasSuccessful (this should be a boolean and at least 2 should be false) Genre Loop through all of the objects in Array If the movie is successful, display all the movie information on the page. These movies were a success: Title: Forrest Gump Year Realeased: 1994 Director: Robert Zemeckis Genre: Comedy
in java Jimmy wants to store course grades and corresponding student last names using two parallel...
in java Jimmy wants to store course grades and corresponding student last names using two parallel arraylists (Double and String). She also wants to identify the average of all the grades. Use a while loop. Prompt the user for each grade and use -1 as the sentinel. Ask for the student name if -1 has not been entered for the grade. Be sure to output the average of the grades. (**Hint: You will need to figure out the sum first)...
Javascript array of objects: I'm trying to get the input into an array of objects, and...
Javascript array of objects: I'm trying to get the input into an array of objects, and then display the information in a table using a for loop, but I don't think my path is right <!DOCTYPE html> <head> <title>Form</title> <meta charset="utf-8" /> <style media="screen"> h1 { text-align: center; } div { background-color: #pink; border: 2px solid green; padding: 15px; margin: 65px; } </style> <script> var list = []; total = 0; text = ""; function Product(item, quantity, costs){ this.item =...
Mini JAVASCRIPT Algorithm Exercise "Sum All In Array" Objectives Create a function that adds all numbers...
Mini JAVASCRIPT Algorithm Exercise "Sum All In Array" Objectives Create a function that adds all numbers of a provided array (arr), accounting for non-integer values in arr. The output should return an integer. Notes Remember your data types? If the element is an integer (8), it should be added. If the element is a string with a number value ("8"), it should be added. If the element is not a number, or if it is a string with a non-number...
Please answer these The following array is declared: int grades[20]; a. Write a printf() statement that...
Please answer these The following array is declared: int grades[20]; a. Write a printf() statement that can be used to display values of the first, third, and seventh elements of the array. b. Write a scanf() statement that can be used to enter values into the first, third, and seventh elements of the array. c. Write a for loop that can be used to enter values for the complete array. d. Write a for loop that can be used to...
Given an array of Student type and size 10, create a linked list of students by...
Given an array of Student type and size 10, create a linked list of students by linking students with an odd index first and then linking students with an even index. Write a loop to print out the students in the linked list #include<iostream> #include<string> #include<fstream> using namespace std; const int NUM = 10; struct Student{ string fName; string lName; Student * next; }; int main() {        Student stuArr[NUM];        ifstream myfile;        myfile.open("Test.txt");        for(int i = 0;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT