JavaScript Object-Oriented JavaScript Getters and Setters Creating Getter Methods

Reagan Ganancial
Reagan Ganancial
9,475 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 ;)

trio interactive
trio interactive
15,321 Points

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,475 Points

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

trio interactive
trio interactive
15,321 Points

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,475 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);

Elijah Quesada
Elijah Quesada
Front End Web Development Techdegree Graduate 31,100 Points

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,475 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"; } }