Skip to content

Instantly share code, notes, and snippets.

@abhisheks-12
Created August 8, 2021 11:49
Show Gist options
  • Save abhisheks-12/9076e013b5ef4e072f165c170c6e4441 to your computer and use it in GitHub Desktop.
Save abhisheks-12/9076e013b5ef4e072f165c170c6e4441 to your computer and use it in GitHub Desktop.
playing with oop js
class UserName {
greet = 'Hello';
constructor(name, age, birthYear, weight) {
this.name = name;
this.age = age;
this.birthYear = birthYear;
this.weight = weight;
// calling methods here
this._greetPeople();
this.isHealthy();
}
_greetPeople() {
return (`${this.greet} ${this.name} you are ${this.age} old`);
}
_calFutureAge(year) {
this.futureAge = year - this.birthYear;
console.log(`The future age will be ${this.futureAge}`);
}
isHealthy() {
// this.fixAge = 100; -----> similar to const ageFix
const ageFix = 100;
if (this.age < ageFix) {
console.log('You are healthy');
} else {
console.log('You are not healthy');
}
}
}
const abhishek = new UserName('Abhishek', 23, 1998, 56);
console.log(abhishek);
abhishek._calFutureAge(2040);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment