Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Ben Dowsett
Ben Dowsett
6,780 Points

Methods in Objects

I am trying to use an if statement in a method to show a message if the email address already exists in an array, not sure where I am going wrong - not throwing any errors just the the If statement doesnt work, any help greatly appreciated

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.includes(studentToRegister.email)) {
            console.log ( `${studentToRegister.email} already registered`)
        }else{
        this.students.push(studentToRegister);
        console.log( `Registering ${studentToRegister.email} to the bootcamp Web Dev Fundamentals.`)

        }

    }
 }

1 Answer

Reggie Williams
STAFF
Reggie Williams
Treehouse Teacher

Hey Ben Dowsett is this code in a workspace that you can share a snapshot of? Try logging out the values of all the variables used in the if statement to see if they are what you're expecting