JavaScript Object-Oriented JavaScript Getters and Setters Creating Getter Methods

Anna Gibson
Anna Gibson
Front End Web Development Techdegree Student 4,468 Points

What Am I Doing Wrong

I'm trying to create an empty getter method, but I keep getting the 'unexpected identifier' error message. Can you let me know what I'm doing wrong?

creating_getters.js
class Student {
    constructor(gpa, credits){
        this.gpa = gpa;
        this.credits = credits;

      get level() {

      }
    }

    stringGPA() {
        return this.gpa.toString();
    }
}

const student = new Student(3.9);
Jake Kobs
Jake Kobs
9,212 Points

Anna, Your alternate constructor is missing a closing curly brace. I think you moved the get level() getter inside the constructor.

1 Answer

Steven Parker
Steven Parker
171,958 Points

It looks like your method is inside the constructor.

It should be a "peer" to the constructor and to the "stringGPA" method.