JavaScript Object-Oriented JavaScript Working with Classes in JavaScript Adding methods to classes

Amanda Otero
Amanda Otero
7,334 Points

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
8,570 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

2 Answers

rydavim
MOD
rydavim
Treehouse Moderator 18,640 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!

Amanda Otero
Amanda Otero
7,334 Points

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
8,570 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