Question

In: Computer Science

[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 the arrays based on the student’s grade.

Display all the grades and names sorted by the grade.

Solutions

Expert Solution

Screenshot of the code:

Code to copy:

<!DOCTYPE html>

<html>

<body>

<script>

// Define the addToArray() function

function addToArray(name, grade, student_name, student_grade)

{

// Add the name to the student_name

student_name.push(name);

// Add the grade to the student_grade

student_grade.push(grade);

}

// Define the displayArr() function

function displayArr(student_name, student_grade, counter)

{

// Declare a variable

var x;

for(x =0; x < counter; x++)

{

// Display the student name and corresponding grade

document.writeln("Student Name: " + student_name[x] + " Grade: " + student_grade[x] + "<br/>");

}

}

// Define the findMaximum() function

function findMaximum(student_name, student_grade, counter)

{

// Assign the first value of the student_grade array

var max_value = student_grade[0];

// Initialize a variable to zero

var max_index = 0;

// Declare a variable

var x;

for(x = 1; x < counter; x++)

{

// Check if the value at index x is greater than

// the value at max_value

if(student_grade[x] > max_value)

{

// Assign the value to max_value

max_value = student_grade[x]

// Assign the value of index to max_index

max_index = x;

}

}

// Display the maximum grade and student's name

document.writeln("Maximum Grade: " + max_value + " Student Name: " + student_name[max_index] + "<br/>");

}

// Define the sortGrade() function

function sortGrade(student_name, student_grade, counter)

{

// Declare the necessary variables

var i, j;

for(i = 0; i < counter; i++)

{

for(j = 0; j < counter - i; j++)

{

// Check if grade at index j is greater than

// the grade at index j+1

if(student_grade[j] > student_grade[j+1])

{

// Swap the elements in the student_grade[] array

var temp_grade = student_grade[j];

student_grade[j] = student_grade[j+1];

student_grade[j+1] = temp_grade;

// Swap the elements in the student_name[] array

var temp_name = student_name[j];

student_name[j] = student_name[j+1];

student_name[j+1] = temp_name;

}

}

}

}

// Declare two arrays

var student_name = [];

var student_grade = [];

// Initialize a counter variable to zero

var counter = 0;

do

{

// Prompt user to enter the name

var name = prompt("Enter the name: ");

// Check if the value in name variable is '???'

if(name == '???')

{

break;

}

// Prompt user to enter the grade

var grade = parseFloat(prompt("Enter the grade: "));

// Call the addToArray() function

addToArray(name, grade, student_name, student_grade);

// Increment the

counter++;

}while(name != '???')

// Call the displayArr() function to display the array

displayArr(student_name, student_grade, counter);

// Call the findMaximum() function to display the

// maximum grade

findMaximum(student_name, student_grade, counter);

// Call the sortGrade() function to sort the array by

// grades

sortGrade(student_name, student_grade, counter);

// Call the displayArr() function to display the array

// after sorting by grades

displayArr(student_name, student_grade, counter);

</script>

</body>

</html>

Sample output:


Related Solutions

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...
<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...
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...
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...
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)...
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1....
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January" through "December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs to adjust the...
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...
Write a java script function that accepts integer array as input, and display a new array...
Write a java script function that accepts integer array as input, and display a new array by performing fol lowing modifications, • The values in odd index positions must be incremented by 1 • The values in even index positions must be decremented by 1. • Assume the array index starts from 0. Input 1: arr = [1,2,3,4] Output 1: arr = [0,3,2,5 it done html and javascript and plz do it in simple way
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT