es6 classes | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

es6 classes

someone could tell me, what I am making wrong here please? You are making a program so that students are able to calculate their average of 3 exam scores. The given program takes the scores of 3 exams as input and declares the Exams class. Add a static method average() to class Exams, which will take the scores as parameters, and calculate and return the average score rounded to the nearest integer so that the code in main works correctly. Sample Input 74 80 68 Sample Output 74 https://code.sololearn.com/WA21a20a13A8

5th Jun 2021, 7:08 AM
JRAMAHES
JRAMAHES - avatar
5 Answers
+ 2
I don't think we have readLine() function in JS. May be it exist in Node.js. may be try something like this. class Exams { constructor(exam1, exam2, exam3) { this.exam1 = exam1; this.exam2 = exam2; this.exam3 = exam3; } static average(x,y,z){ var sc = (x+y+z) / 3; return Math.round(sc); } } console.log(Exams.average(1,2,3));
5th Jun 2021, 7:28 AM
Aravind Shetty
Aravind Shetty - avatar
+ 1
creating your constructor with the three inputted exam scores, adding a static method called average that you were told to use with the same exam scores as a parameter, and returning a rounded variable where you carry on your operation will also help solve the problem. //your code goes here constructor(exam1, exam2, exam3){ this.exam1 = exam1; this.exam2 = exam2; this.exam3 = exam3; } static average(exam1, exam2, exam3){ const myAvg = (exam1 + exam2 + exam3)/3; return Math.round(myAvg); }
8th Feb 2022, 5:10 PM
ENOCH KWATEH DONGBO
ENOCH KWATEH DONGBO - avatar
+ 1
try this code function main() { var exam1 = parseInt(readLine(), 10); var exam2 = parseInt(readLine(), 10); var exam3 = parseInt(readLine(), 10); console.log(Exams.average(exam1,exam2,exam3)); } class Exams{ //your code goes here constructor(satu,dua,tiga) { this.satu = satu; this.dua = dua; this.tiga = tiga; } static average(ex1,ex2,ex3){ return Math.round((ex1 + ex2 + ex3) / 3); } }
10th Dec 2022, 2:42 AM
Hoamppp
Hoamppp - avatar
+ 1
function main() { var exam1 = parseInt(readLine(), 10); var exam2 = parseInt(readLine(), 10); var exam3 = parseInt(readLine(), 10); console.log(Exams.average(exam1,exam2,exam3)); } class Exams{ static average(a,b,c){ return Math.round((a+b+c)/3); } } None of the above suguested codes worked for me. So here, this one actually works for me.
25th Feb 2023, 10:09 AM
Heartlesss B%i%c%H
Heartlesss B%i%c%H - avatar
- 1
make sense to me know, thanks brother!!!
5th Jun 2021, 7:47 AM
JRAMAHES
JRAMAHES - avatar