Skip to content

Instantly share code, notes, and snippets.

@Caballerog
Created June 14, 2024 11:07
Show Gist options
  • Save Caballerog/fd93d6982d65b2efbc1bd9ea1bcd64a4 to your computer and use it in GitHub Desktop.
Save Caballerog/fd93d6982d65b2efbc1bd9ea1bcd64a4 to your computer and use it in GitHub Desktop.
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