In: Computer Science
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 using showAlltheGrades
method.
NOTE: Make sure to use the push() method when adding elements to the arrays.
Prefer to use NotePad++ or Note Pad to type code. Please add on to the Pseudo Code and convert it into the javascript needed. Thank you
PLEASE USE THE REFERENCE JAVASCRIPT CODE BELOW!
[Reference JavaScript code]
<<html>
<body>
<script>
// Declare a class
class Student {
// initialize an object
constructor(grade, name) {
this.grade=grade;
this.name=name; }
//Declare a method
detail() {
document.writeln(this.grade + " " +this.name)
}//detail
}//class
var student1=new Student(1234, "John Brown");
var student2=new Student(2222, "Mary Smith");
student1.detail();//call a method
student2.detail();
</script>
</body>
</html>
[Find max pseudo code]
max← A[1]
while i < 10
if A[i] > max
max = A[i]
i ← i + 1
end while
<html> <body> <script> // Declare a class class Student { // initialize an object constructor(grade, name) { this.grade=grade; this.name=name; } //Declare a method detail() { document.writeln(this.grade + " " +this.name + "</br>") }//detail }//class students = Array(); function inputGrade() { for(var i=0; i<2; i++) { var name = prompt('Enter name of student ' + (i + 1)) var grade = parseInt(prompt('Enter marks of student ' + (i + 1))) students.push(new Student(grade, name)); alert(students[i].grade); } } function showAlltheGrades() { for(var i=0; i<students.length; i++) { students[i].detail(); } } function findMaxGrade() { var max = students[0]; for(var i=1; i<students.length; i++) { if(students[i].grade > max.grade) { max = students[i]; } } document.writeln("</br>Student with max grade:") max.detail(); } inputGrade(); showAlltheGrades(); findMaxGrade(); </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.