For my school project, I'm struggling to retrieve the names from a class using a method. One class creates monsters and another extends it.
abstract class genMonster {
constructor(
public id: string,
public name: string,
public weaknesses: string[],
public location: string,
public challenge: number,
public mortality: boolean = false,
public safety: number,
) {}
monsterLogger() {
return this
}
}
class ghost extends genMonster {
constructor(id: string, name: string, weaknesses: string[], location: string, challenge: number, mortality: boolean, safety: number, public type: string, public signs: string[]) {
super(id, name, weaknesses, location, challenge, mortality, safety);
}
get info() {
return console.log(this.name, this.type, this.signs);
}
}
I have created some monster objects:
const Jerry = new ghost("0234", "Jerry", ["soap", "attractive people"], "-74.4835, 171.4803", 3, false, 2, "boring", ["libra", "ectoplasm puddles", "yamaha piano music"]);
const Patricia = new ghost("8765", "Patricia", ["being sent to the corner", "milk and cookies"], "-89.3921, -30.4079", 1, false, 2, "spooky", ["stray drawing supplies", "messy living rooms", "spilled milk"]);
const Lola = new ghost("4569", "Lola", ["makeup remover", "tied shoelaces"], "-61.6134, -90.1008", 10, false, 10, "boss music", ["water tasting like cotton candy", "spontaneous laughing", "socks mysteriously becoming fun and colorful"]);
Here is the method I attempted that isn't working as expected:
class organize extends genMonster{
constructor(id: string, name: string, weaknesses: string[], location: string, challenge: number, mortality: boolean, safety: number){
super(id, name, weaknesses, location, challenge, mortality, safety)
}
public static getNames(){
return this.name
}
}
console.log(organize.getNames());
//logs 'organize'
Any assistance would be greatly appreciated!