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 Getters and Setters Creating Getter Methods

Reagan Ganancial
Reagan Ganancial
9,476 Points

Challenge Task 1 of 2 Inside the Student class, create an empty getter method called level(). { I'am stuck!}

It keeps on saying on expected identifiers.

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

    stringGPA() {
        return this.gpa.toString();
    }
  get level() {
      const student = new Student(3.9);
      const credits = student;
      if (credits > 90) {
        return 'Senior';
      } else if (credits > 61 && creits <= 90) {
        return 'Junior';    
      } else if (credits > 31 && creits <= 60) {
        return 'Sophomore';
      } else {
        return 'Freshman';
      }
}

const student = new Student(3.9);

3 Answers

Antonio De Rose
Antonio De Rose
20,885 Points
  get level() {
      const student = new Student(3.9); //why this line
      const credits = student; //why this line
      if (credits > 90) {
        return 'Senior';
      } else if (credits > 61 && creits <= 90) { //between, shouldn't it be including 61, check spelling on credits
        return 'Junior';    
      } else if (credits > 31 && creits <= 60) { //between shouldn't it be including 31, see spelling for credits
        return 'Sophomore';
      } else {
        return 'Freshman';
      }
}

//you are missing a keyword, when you are calling class level property, please use it
//you cannot directly use, credits, as in a whole, you need a the dot operator, and the keyword in front
Starky Paulino
seal-mask
.a{fill-rule:evenodd;}techdegree
Starky Paulino
Front End Web Development Techdegree Student 6,398 Points

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

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

set major(name) {

}

get level() {
    if (this.credits > 90 ) {
        return 'Senior';
    } else if (this.credits > 60) {
        return 'Junior';
    } else if (this.credits > 30) {
        return 'Sophomore';
    } else {
        return 'Freshman';
    }
}

}

var student = new Student(3.9, 60);

restart the challenge and place your piece of code on line 6 it won't take it anywhere else. Has to go after the class and before the GPA