Generation

generate functionSun, 13 Nov 2022

class to create objects storing age, name, and cost

class Animal { constructor(age, name, cost) { this.age = age; this.name = name; this.cost = cost; } getDetails() { return `${this.name} is ${this.age} years old and costs ${this.cost}`; } } const animalDetails = new Animal(4, 'dog', '$4,000'); console.log(animalDetails.getDetails());

Javascript
Generate More

Questions about programming?Chat with your personal AI assistant