My code show me this error "Unexpected token. A constructor, method, accessor, or property was expected.ts(1068)
class animal {
constructor(especie,edad,color){
this.especie = especie;
this.edad = edad;
this.color = color;
this.info = `Soy un ${this.especie}, tengo ${this.edad}
y soy de color ${this.color}`;
}
this.verInfo = ()=>{
document.write(this.verInfo);
}
}
The error show it in this .verInfo
You'd want to rewrite it as follows:
Maybe read about classes here. This is a really good reference to start with: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
Also you may to rename animal
as Animal
.
class Animal {
constructor(especie,edad,color){
this.especie = especie;
this.edad = edad;
this.color = color;
this.info = `Soy un ${this.especie}, tengo ${this.edad}
y soy de color ${this.color}`;
}
verInfo = () =>{
document.write(this.verInfo);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.