0

Please help me in understanding the undefined result

There have been a ton of conceptual answers, but could someone break it down into a simple resolution? function main() { var exam1 = parseInt(readLine(), 10); var exam2 = parseInt(readLine(), 10); var exam3 = parseInt(readLine(), 10); Exams.average(exam1,exam2,exam3); } class Exams{ //your code goes here constructor(e1,e2,e3){ this.e1 = e1; this.e2 = e2; this.e3 = e3; } static average(e1,e2,e3){ const avg = (e1+e2+e3)/3; return Math.round(avg); } } const avg = new Exams() console.log(Exams.average());

27th Apr 2021, 11:13 AM
Lee 4 Code
Lee 4 Code - avatar
8 Antworten
+ 1
// here's the correct code function main() { var exam1 = 56; var exam2 = 65; var exam3 = 87; console.log("The average is", Exams.average(exam1,exam2,exam3)); } class Exams{ //your code goes here constructor(e1,e2,e3){ this.e1 = e1; this.e2 = e2; this.e3 = e3; } static average(e1,e2,e3){ const avg = (e1+e2+e3)/3; return Math.round(avg); } } const avg = new Exams() main()
27th Apr 2021, 11:22 AM
minirkk
minirkk - avatar
+ 1
S C Lee I'm batting a 1000 today(not really) I made a mistake in my earlier post. You don't need to invoke main() just remove it and you code will work.
27th Apr 2021, 1:56 PM
ODLNT
ODLNT - avatar
0
that created an input alert box? That did not help.
27th Apr 2021, 11:17 AM
Lee 4 Code
Lee 4 Code - avatar
0
Placing values in the code doesn't call the random values of the test cases Didn't work without them. Any other suggestions?
27th Apr 2021, 11:34 AM
Lee 4 Code
Lee 4 Code - avatar
0
Why dies it not call the random values (exam scores) from the main?
27th Apr 2021, 11:35 AM
Lee 4 Code
Lee 4 Code - avatar
0
Sorry about leaving you hi and dry yesterday. You need to call the function main(), get rid of the last two lines at end of your code "const avg = new Exams() console.log(Exams.average());" and add main()
27th Apr 2021, 11:54 AM
ODLNT
ODLNT - avatar
0
my latest effort returned NaN function main() { var exam1 = parseInt(readLine(), 10); var exam2 = parseInt(readLine(), 10); var exam3 = parseInt(readLine(), 10); console.log("average is", Exams.average(exam1,exam2,exam3)); } class Exams{ //your code goes here constructor(e1,e2,e3){ this.e1 = e1; this.e2 = e2; this.e3 = e3; } static average(e1,e2,e3){ const avg = (e1 + e2 + e3)/3; return Math.round(avg); } } main()
27th Apr 2021, 1:05 PM
Lee 4 Code
Lee 4 Code - avatar
0
ODLNT thank you for clearing that up. Still a bit foggy on why it got there, but let's take the win!
27th Apr 2021, 2:04 PM
Lee 4 Code
Lee 4 Code - avatar