js/6/pets.html
2024-10-03 11:29:13 -05:00

35 lines
713 B
HTML

<html><body><script>
function Cat(name) {
this.name = name;
}
Cat.prototype.sayHello = function () {
console.log(`Miaow! My name is ${this.name}.`);
};
let kiki = new Cat("Kiki");
kiki.sayHello();
class Dog {
constructor(name) {
this.name = name;
}
sayHello() {
console.log(`Woof! My name is ${this.name}.`);
}
}
let felix = new Dog("Felix");
let moona = new Cat("Moona");
moona.sayHello = function () {
console.log(`HELLO!!! I'M ${this.name.toUpperCase()}!`);
};
moona.sayHello();
let yappy = new Dog("Yappy");
yappy.sayHello = function (){
console.log(`Bark Bark! I'M ${this.name.toUpperCase()}!`)
}
yappy.sayHello();
felix.sayHello();
</script></body></html>