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

2018 object oriented challenge

Your conditional statement is returning the wrong student level... I'am always getting this..

creating_getters.js
class Student {
    constructor(gpa, credits){
        this.gpa = gpa;
        this.credits = credits;
    }
  get level () {    
    const credits = this.credits;
    if (credits > 90) {
      return 'senior';
    } else if (credits > 61 && credits <= 90) {
      return 'junior';
    } else if (credits > 31 && credits <= 60) {
      return 'sophomore';
    } else {
      return 'freshman';
    }
  }
}

const student = new Student(3.9);

6 Answers

Just putting this here:

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

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

    get level() {
      const credits = this.credits;
      if(credits > 90) {
        return "Senior";
      } else if(credits > 60 && credits < 91) {
        return "Junior";
      } else if(credits > 30 && credits < 61) {
        return "Sophomore";
      }
      return "Freshman";
    }
}

With between 31 and 60 they mean: bigger than 30 and smaller than 61 ;)

Yes. Because you're including the value 30 in the conditional for 'Sophomore' when it should be part of the 'Freshman' conditional. Change the value to 31 since you're now using the equals sign too.

Reagan Ganancial
Reagan Ganancial
9,476 Points

Yehey! this one is correct and thank you very much!

Hey!

Your code is omitting the values 31 and 61 because you are using the greater than operator. Switch 31 with 30 and 61 with 60 in your code and it should be valid.

Also sometimes workspaces is looking for an exact output and can be very specific about answers so if you're still having trouble try capitalizing the first letter of each string (as in the challenge instructions).

Hope this helps!

Reagan Ganancial
Reagan Ganancial
9,476 Points

it still won't work;

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

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

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

const student = new Student(3.9);

You could also just add two equal signs to make it greater than or equal.

class Student {
    constructor(gpa, credits){
        this.gpa = gpa;
        this.credits = credits;
    }
  get level () {    
    const credits = this.credits;
    if (credits > 90) {
      return 'senior';
    } else if (credits >= 61 && credits <= 90) {
      return 'junior';
    } else if (credits >= 31 && credits <= 60) {
      return 'sophomore';
    } else {
      return 'freshman';
    }
  }
}

const student = new Student(3.9);
Reagan Ganancial
Reagan Ganancial
9,476 Points

STILL NOT WORKING.. HUHUHU..

class Student {

constructor(gpa, credits){

    this.gpa = gpa;

    this.credits = credits;

}

stringGPA() {

    return this.gpa.toString();

}

get level () {

const credits = this.credits;

if (credits > 90) {

  return 'Senior';

} else if (credits >= 61 && credits <= 90) {

  return 'Junior';

} else if (credits >= 30 && credits <= 60) {

  return 'Sophomore';

} else {

  return 'Freshman';

}    

}

}

const student = new Student(3.9);

I have tried my code in asending and decending order and is still receiving the message: "Your conditional is returning the wrong student level". See code:

get level(){ if(this.credits <=30){ return "Freshman"; } else if(this.credits >= 31 && this.credits <= 60){ return "Sophmore"; } else if(this.credits >= 61 && this.credits <= 90){ return "Junior"; } else if(this.credits >= 91){ return "Senior"; } }

get level(){ const credits = this.credits; if(this.credits >=91){ return "Senior"; } else if(this.credits >= 61 && this.credits <= 90){ return "Junior"; } else if(this.credits >= 31 && this.credits <= 60){ return "Sophmore"; } else if(this.credits >= 30){ return "Freshman"; } }