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

<HTML JAVASCRIPT> Please create an array of student names and another array of student grades. Create...
<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...
[JAVA SCRIPT] Please create an array of student names and another array of student grades. Create...
[JAVA SCRIPT] 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...
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: - 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...
Making a blackjack game in javascript Create a function called createDeck() that will create an array...
Making a blackjack game in javascript Create a function called createDeck() that will create an array of objects (52). Each object contains two properties: suit and value. The suit property will be either 'Hearts', 'Clubs', 'Diamonds', or 'Spades'. The value property will be either 'Ace', 'King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven', 'Six', 'Five', 'Four', 'Three' , or 'Two''. Note: We will probably want to store possible suits and values in separate arrays. Create a function called shuffleDeck() that will...
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
Write a PHP script that: 1) Has an associative array with 10 student names and test...
Write a PHP script that: 1) Has an associative array with 10 student names and test scores (0 to 100). ie. $test_scores('John' => 95, ... ); 2)Write a function to find the Average of an array. Input is an array, output is the average. Test to make sure an array is inputted. Use ARRAY_SUM and COUNT. 3)Output the test scores highest to lowest, print scores above the average in Green. Find a PHP Sort function for associative arrays, high to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT