swati-jagtap / javascript-practice

0 stars 0 forks source link

15.1.1--Create an Animal class. The class will have name, age, color, legs properties and create different methods #152

Open swati-jagtap opened 3 years ago

swati-jagtap commented 3 years ago

 class Animal{
     constructor(name,age,color,legs){
         this.name=name;
         this.age=age;
         this.color=color;
         this.legs=legs;

         console.log(this)  //1

     }

   get getinfo(){
       return `${this.name.toUpperCase()} is my pet.${this.name} is ${this.age} yers old.`;
   }
   setName(){
       this.owner="johny";
     // let Name=this.name.toUpperCase();
       return `${this.owner} was his owner`;
      // return `${Name}`;
   }
   birthYear(){
     const d=new Date();
     const Birth=d.getFullYear()-this.age;
     return `${this.name}'s Year Of Birth is : ${Birth}`;
   }
 }
 const A1=new Animal("tyson",2,"brown",4);
 console.log(A1.getinfo);
 console.log(A1.setName());
 console.log(A1.birthYear());
 console.log(A1);      //2
 console.log(Animal)     //3
 console.log(A1.name);      //4

image