I tried to search a lot on google but can’t find the answer. That’s why asking here. This is my code.
class student {
static i = 1;
constructor(name) {
this.studentName = name;
this.studentRollno = this.i;
student.i++;
}
into() {
console.log(`Hello guys! My name is ${this.studentName} and my roll no. is ${this.studentRollno}. Nice to meet you.`);
}
}
let a = new student("Nitigya Joshi");
a.into();
What I want to do is update the variable I whenever an object of student class is made to automatically assign roll no. serial-wise. But when I try to run this code, I get output but in place of roll no. it say’s undefined. Can’t figure out the error.
Output:
Hello guys! My name is Nitigya Joshi and my roll no. is undefined. Nice to meet you.