Asking for the initialization of 'Exams'. But how to.. ? Please help me to solve it out! Thanks in advance! | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Asking for the initialization of 'Exams'. But how to.. ? Please help me to solve it out! Thanks in advance!

var exam1 = 74; var exam2 = 80; var exam3 = 68; console.log(Exams.average(exam1, exam2, exam3)); class Exams{ static average(a, b, c){ return Math.round((a + b + c)/3); } };

1st Feb 2023, 7:21 AM
Sony
Sony - avatar
5 Antworten
+ 4
Move class `Exams` definition up before the line where Exams.average() was invoked. I'm just guessing class definition must preceed its usage.
1st Feb 2023, 7:57 AM
Ipang
+ 3
Sony, Move your function call console.log(Exams.average(exam1, exam2, exam3)); To beneath the class definition and it runs fine 👍. You can’t use hoisting with an unitialized class, this is because the class could be extended. Hopefully that makes sense.
1st Feb 2023, 8:13 AM
DavX
DavX - avatar
+ 1
Ipang outstanding... :) Bravo!! Thanks to all..
1st Feb 2023, 8:06 AM
Sony
Sony - avatar
+ 1
DavX yeah.. it's Indeed!! Thanks!
1st Feb 2023, 8:38 AM
Sony
Sony - avatar
0
But in output, it's asking for the 'Exams' initialization..? Mirielle
1st Feb 2023, 7:28 AM
Sony
Sony - avatar