Methods 4/12


#1

Hello, guys, need help :slight_smile:

class Surgeon {
constructor(name, department) {
this._name = name;
this._department = department;
this._remainingVacationDays = 20;
}

get name(){
return this._name;
}

get department(){
return this._department;
}

get remainingVacationDays(){
return this._remainingVacationDays;
}

takeVacationDays(daysOff) {
this._remainingVacationDays - daysOff; // can’t understand what do they want from me
}
/*
6. Under the remainingVacationDays getter, create a method called takeVacationDays that accepts one argument named daysOff.

Inside of the method, subtract daysOff from the number saved to _remainingVacationDays. Set _remainingVacationDays to the result. <- What does it mean??
*/
}

const surgeonCurry = new Surgeon(‘Curry’, ‘Cardiovascular’);
const surgeonDurant = new Surgeon(‘Durant’, ‘Orthopedics’);

https://www.codecademy.com/courses/learn-javascript-classes/lessons/classes/exercises/methods?action=resume_content_item&course_redirect=introduction-to-javascript#


#2

we need to update remainingVacationDays variable, so we know how many vacationDays employees have left.


#3

ok, so what do a i need to change in my scrypt or prepend?


#4

here:

this._remainingVacationDays - daysOff;

you calculate how many vacation days an employee has left after taking some days off, but you do nothing with the result of this subtraction, you need to store this in a variable


#5

I did it. Watch the scrypt please


#6

Hey, I also stuck somehow at the same thing. Mainly I saw the difference between

this._remainingVacationDays - daysOff; // which also was my answer and wondering why it was wrong.

and the correct answer:

this._remainingVacationDays -= daysOff;

Can someone explain me why ’ - ’ is wrong and why we need ’ -= ', because I can’t remember another modul was teaching me that so I was very confused.


#7

because x -= y --> x = x - y


in russian, because i’m from Ukraine;)


#8

-= is a shorthand, without the shorthand it would be:

this._remainingVacationDays = this._remainingVacationDays - daysOff;

it will update/re-assign the variable, doing this._remainingVacationDays - daysOff; gives you the subtraction, but you do nothing with the result of the subtraction.


#9

Thanks, figured it out.)