diff --git a/ObjectiveMadness/script.js b/ObjectiveMadness/script.js index e437a44..0a59d5d 100644 --- a/ObjectiveMadness/script.js +++ b/ObjectiveMadness/script.js @@ -89,4 +89,76 @@ underwear.displayProduct(); underwear.displayPrice(); underwear.calculateTotal(); -//https://youtu.be/lfmg-EJ8gm4?si=KJ_EBH2FxCEtonyR&t=19910 \ No newline at end of file +//https://youtu.be/lfmg-EJ8gm4?si=KJ_EBH2FxCEtonyR&t=19910 + + + +//INHERITANCE + +class Animals{ + alive = true + constructor(name, age){ + this.name = name; + this.age = age; + } + + eat(){ + console.log(`This ${this.name} is eating`); + } + + sleep(){ + console.log(`This ${this.name} is sleeping`); + } + move(){ + console.log(`The ${this.name} is mowing with ${this.speed} km/h!!`) + } +} + +class Rabbit extends Animals{ + constructor(name, age, speed){ + super(name, age); + this.speed = speed; + } + run(){ + console.log(`This ${this.name} is running`); + } + set sname(newName){ + this._name = newName + } + get _name(){ + return this._name + } +} + +class Fish extends Animals{ + constructor(name, age, speed){ + super(name, age); + this.speed = speed; + } + swim() { + console.log(`This ${this.name} is swimming like a rabbit, hopping through the water!`); + } +} + +class Hawk extends Animals{ + constructor(name, age, speed){ + super(name, age); //BEFORE constructing the child we NEED to construct the parent with the super() function!!! + this.speed = speed; + } +} + +let fish = new Fish("izé", 4, 25); +const rabbit = new Rabbit("nyuszi",5 ,23 ); +const hawk = new Hawk("Man", 5, 80); + +console.log(fish.alive) +fish.eat(); +rabbit.sleep(); +rabbit.run(); +hawk.sleep(); +console.log(hawk.speed); + +rabbit.move(); +fish.move(); +hawk.move(); +