Question
I did this on visual studio code programming language javascript my code so far //[student1,student2,student3,student4]; varstudents=[ { FirstName1:First1, LastName1:Last1, marks1:[80.89,78.23,68.09] }, { FirstName2:First2, LastName2:Last2, marks2:[90.89,73.93,88.09]
I did this on visual studio code
programming language javascript
my code so far
//[student1,student2,student3,student4];
varstudents=[
{
FirstName1:"First1",
LastName1:"Last1",
marks1:[80.89,78.23,68.09]
},
{
FirstName2:"First2",
LastName2:"Last2",
marks2:[90.89,73.93,88.09]
},
{
FirstName3:"First3",
LastName3:"Last3",
marks3:[50.89,83.23,68.09]
},
{
FirstName4:"First4",
LastName4:"Last4",
marks4:[70.89,93.23,56.09]
}
]
functiongetAvg(students){
consttotal=students.reduce((acc,c)=>acc+c,0);
returntotal/students.length;
}
constaverage=getAvg(students);
console.log(average);
I got stuck on how to go about the mark array and if I am creating my array correctly
What I was trying to create was:
Make an array of 4 students, each student is an object, with the following 4 properties and 1 function.
Properties:
firstName: string, student's first name
middleName: string, student's middle name
lastName: string, student's last name
marks: array of 3 numbers which stands for the marks the student obtained for 3 subjects
e.g, [ 80.89, 78.23, 68.09]
which means this student got 80.89 for subject 1, 78.23 for subject 2, 68.09 for subject 3.
function:
getAvg: calculate the average mark the student earned for all 3 subjects,
and return that average mark.
For each student, display the information as follows:
(first name middle name last name) is a ( level ) student for ( subject1 ), ( level ) for ( subject2 ) ( level ) for ( subject3 )
To get the average mark is (average mark with 2 decimals, obtained from the above object function: getAvg()).
Where:
level is one of the following under the corresponding condition:
"super": if the student's mark is over and including 90
"good": if the student's mark is over and including 80 and less than 90
"potential good": if the student spent less than 80
refer to the following sample output.
I am trying to hard code the data for the 4 students, but I cannot hard-code the calculation or the display.
I am trying to make the program in the future able to easily extend to 10 or 1000 students.
Data:
The construct of the array of 4 student objects based on the data below:
First Name | Middle Name | Last Name | marks for (subject1, subject2, subject3) ========================================================================
"First1" "Middle1" "Last1" 80.89, 78.23, 68.09
"First2" "Middle2" "Last2" 90.89, 73.93, 88.09
"First3" "Middle3" "Last3" 50.89, 83.23, 68.09
"First4" "Middle4" "Last4" 70.89, 93.23, 56.09
Sample output:
first1 Middle1 last1 is a
good student for subject1,
potential good student for subject2,
potential good student for subject3.
His average mark is 75.74 for all subjects.
===============================================
first2 Middle2 last2 is a
super student for subject1,
potential good student for subject2,
good student for subject3.
His average mark is 84.30 for all subjects.
===============================================
first3 Middle3 last3 is a
potential good student for subject1,
good student for subject2,
potential good student for subject3.
His average mark is 67.40 for all subjects.
===============================================
first4 Middle4 last4 is a
potential good student for subject1,
super student for subject2,
potential good student for subject3.
His average mark is 73.40 for all subjects.
===============================================
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started