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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Hanwen Zhang](https://uploads.teamtreehouse.com/production/profile-photos/11590826/micro_Picture.jpg)
Hanwen Zhang
20,084 PointsI don't quite understand why do we need to use the method here in the class syntax?
class Pet { constructor(animal, age, breed, sound) { this.animal = animal; this.age = age; this.breed = breed; this.sound = sound; }
speak() { console.log(this.sound); }
class Student { constructor(gpa){ this.gpa = gpa; } stringGPA() { return this.gpa = "gpa"; } } const student = new Student (3.9);
What happens if we don't use the method?
1 Answer
![Mark Casavantes](https://uploads.teamtreehouse.com/production/profile-photos/11620171/micro_thumb_Mark_Casavantes_Pic.jpg)
Mark Casavantes
2,880 PointsHello Hanwen,
Functions or methods are used to break your code into smaller parts. When you write a large program you can work on one method at a time to make sure it works properly.
If you do not use methods, you just have one program that does everything.
I hope this is helpful to you.
Blake Larson
13,014 PointsBlake Larson
13,014 PointsAre you asking why we use the
new Student(3.9)
syntax?