<HTML 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.
[Report]
Please copy the JavaScript code output (HTML) in either Notepad++ or NotePad
<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>
please upvote.
Get Answers For Free
Most questions answered within 1 hours.