Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Hazim Bora Alap
Hazim Bora Alap
15,001 Points

Object Oriented

I was messing with the code and tried this. I still didn't grasp the difference between objects for some reason but I was trying to convert this example to object oriented way.

'use strict';

let classroom = new Set();

function Student (name, age) { this.name = name, this.age= age }

var steven = new Student( 'Steven',22 ); var sarah = new Student( 'Sarah',23 ); var stevens = new Student( 'Steven', 22 );

if (Student.has(steven)){ console.log( this.name + ' is in the classroom ' + this.age + ' years old') }

When I do this it says .has is not a function. Does that mean, I can't use .has function with constructors?


Kyle Jensen
Kyle Jensen
Courses Plus Student 6,293 Points

You are using two different types here. One is an object Constructor for the Student object and the other is a new Set for classroom. ".has()" is method of Set(). The way I recall the lesson was that we used object literal notation for creating each student object with key/value pairs and then used the method of Set() called ".add()". so let Steven = {name: 'Steven', age: 22 }; classroom.add(Steven); and then if (classroom.has(Steven)){ console.log( this.name + ' is in the classroom and he is ' + this.age + ' years old') }