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 Object-Oriented JavaScript Working with Classes in JavaScript Adding methods to classes

Why this is not working? it says is not a function.

Inside the stringGPA() method, convert the value of the gpa property to a string and return it.

adding_methods.js
class Student {
    constructor(gpa, stringGPA){
        this.stringGPA = stringGPA;
        this.gpa = gpa;
    }

  stringGPA(){
    const string = this.gpa.toString();
    return string;
  }

}


const student = new Student(3.9);
Alan Villarreal
Alan Villarreal
19,266 Points

hey don't know why but I I try what you did and I got it right don't know why you got it wrong

you don't need to put the stringGPA method as a parameter of the constructor method.

Ex:

class Student { constructor(gpa){ this.gpa = gpa; }

stringGPA(){ const string = this.gpa.toString(); return string; }

}

const student = new Student(3.9);

2 Answers

rydavim
rydavim
18,813 Points

It looks like you may have gotten a bit side tracked from the challenge task. Using the code from the first task (below) you should write code inside the stringGPA method to convert the gpa value into a string. You don't need to change anything about the constructor.

class Student {
  constructor(gpa){ // leave this alone
    this.gpa = gpa;
  } 
  stringGPA(){ // this is the empty method from task 1
    // task 2 code goes here
  }
}
const student = new Student(3.9);

You'll be using this.gpa again, and you only need to write a return statement inside the stringGPA method - such that it returns the value of gpa from the constructor as a string.

Hopefully that helps, but let me know if it's still giving you trouble and we can walk through a more complete solution. Good luck, and happy coding!

Alan Villarreal, thank you so much, Alan, I had to close my browser and check again and it did work that time, it was really weird, sometime treehouse challenge has little glitches like that i guess.

Alan Villarreal
Alan Villarreal
19,266 Points

yup I know I have problems that I takes long answer me if im wrong or right an it tells me that I have to restart