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!

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


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') }