Created
August 8, 2021 11:49
-
-
Save abhisheks-12/9076e013b5ef4e072f165c170c6e4441 to your computer and use it in GitHub Desktop.
playing with oop js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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