JavaScript Object-Oriented JavaScript Getters and Setters Creating Getter Methods

Reagan Ganancial
Reagan Ganancial
9,475 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,855 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
Starky Paulino
Front End Web Development Techdegree Student 6,383 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);

Simone Beaver
Simone Beaver
Full Stack JavaScript Techdegree Graduate 15,717 Points

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