Hey everyone! I've written some code and need help fixing it so that the if statement works properly when adding the same student. Thanks so much for any assistance!
class Student {
constructor(name, email, community) {
this.name = name;
this.email = email;
this.community = community;
}
}
class Bootcamp {
constructor(name, level, students = []) {
this.name = name;
this.level = level;
this.students = students;
}
registerStudent(studentToRegister) {
if (this.students.forEach(s => s.email === s.email)) {
console.log(`The student ${studentToRegister.email} is already registered!`);
} else {
this.students.push(studentToRegister);
console.log(`Registering ${studentToRegister.email} to the bootcamp ${this.name}.`);
}
return this.students;
}
}
// Testing the code
// Creating new Bootcamps
const webDevFund = new Bootcamp("Web Dev Fundamental", "Beginner");
const fullStack = new Bootcamp("Full Stack Web Dev", "Advanced");
// Adding students to Bootcamps
const Max = new Student("Max", "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="91fcf0e9d1f7e8f0e3f5bffff4e5">[email protected]</a>", "PAP");
const Bird = new Student("Bird", "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="15777c677155736c7467713b7b7061">[email protected]</a>", "Cap-Haitien");
const Yayad = new Student("Yayad", "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2d544c544c496d4b544c5f4903434859">[email protected]</a>", "Cayes");
const Meg = new Student("Meg", "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="39545c5e795f40584b5d17575c4d">[email protected]</a>", "Miami");
// Verifying registrations
webDevFund.registerStudent(Bird);
webDevFund.registerStudent(Max);
fullStack.registerStudent(Yayad);
fullStack.registerStudent(Meg);
fullStack.registerStudent(Yayad);