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 trialAmanda Otero
7,410 PointsWhy 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.
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);
Karina Machado
5,999 Pointsyou 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
18,814 PointsIt 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
7,410 PointsAlan 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
20,530 Pointsyup 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
Alan Villarreal
20,530 PointsAlan Villarreal
20,530 Pointshey don't know why but I I try what you did and I got it right don't know why you got it wrong