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());
8 Respuestas
+ 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()
+ 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.
0
that created an input alert box?
That did not help.
0
Placing values in the code doesn't call the random values of the test cases
Didn't work without them. Any other suggestions?
0
Why dies it not call the random values (exam scores) from the main?
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()
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()
0
ODLNT thank you for clearing that up. Still a bit foggy on why it got there, but let's take the win!