This is a part of my class Bird
:
class Bird
{
constructor()
{
this.imagePaths = ['./assets/Bill-Gates.png', './assets/steve-jobs.png', './assets/zuckerberg.png'];
this.elementImg.src = this.changeImage();
this.speed = Math.floor((Math.random() * 5) + 5);
}
In the class's constructor, I want to react to different speeds and assign different images to the object:
changeImage = () => {
if (this.speed < 6) {
return this.imagePaths[0];
}
else if (this.speed < 9) {
return this.imagePaths[1];
}
else if (this.speed > 9) {
return this.imagePaths[2];
}
}
I try to do this by assigning the images to the elementImg.src
property via a method. But the method does not return the desired value. Why?