Created
June 14, 2024 11:07
-
-
Save Caballerog/fd93d6982d65b2efbc1bd9ea1bcd64a4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 VirtualPet { | |
name: string; | |
color: string; | |
abilities: string[]; | |
energyLevel: number = 0; | |
constructor(name: string, color: string, abilities: string[]) { | |
this.name = name; | |
this.color = color; | |
this.abilities = abilities; | |
this.calculateEnergy(3000) | |
} | |
private calculateEnergy(milliseconds: number) { | |
const start = new Date().getTime(); | |
let end = start; | |
console.log(`Initializing ${this.name}...`); | |
while (end < start + milliseconds) { | |
end = new Date().getTime(); | |
} | |
this.energyLevel = 100; | |
} | |
displayInfo() { | |
console.log(`Name: ${this.name}, Color: ${this.color}, Abilities: ${this.abilities.join(', ')}, Energy Level: ${this.energyLevel}`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment