Query, why when showing images with this for method, shows only the array " Collection.push " but I can not display strong> the array " images " with the same method for changing the for parameter (var objects of collection ) for the for (var objects of images )?.
I do not throw any errors in console but it shows nothing once I change images for collection .
Greetings and thank you very much!
var imagenes=[];
imagenes["Cauchin"]="vaca.png";
imagenes["Pocacho"]="pollo.png";
imagenes["Tocinaurio"]="cerdo.png";
var coleccion=[];
coleccion.push(new Pakiman("Pocacho",100,30));
coleccion.push(new Pakiman("Tocinaurio",150,70));
coleccion.push(new Pakiman("Cauchin",50,40));
for (var objetos of coleccion)
{
console.log(objetos);
objetos.mostrar();
}
class Pakiman
{
constructor(n,v,a)
{
this.imagen= new Image();
this.nombre=n;
this.vida=v;
this.ataque=a;
this.imagen.src=imagenes[this.nombre];
}
hablar()
{
document.writeln(this.nombre+" <strong>dice</strong>:
"+this.nombre+"..."+this.nombre+"<br/>")
}
mostrar()
{
document.body.appendChild(this.imagen);
document.writeln("<br/>"+"<strong>Nombre: </strong>"+this.nombre+"
<br/>"+"<strong>Vida: </strong>"+this.vida+"<br/>"+"<strong>Ataque:
</strong>"+this.ataque+"<br/>");
}
}
With the parameter
for (var objects of collection )
with the parameter for (var objects of images )