Currently, I am delving into the realm of JavaScript and encountering some hurdles with arrays in this programming language. My task at hand is to create a class named TV Show that includes attributes such as title, thematic element, and an array of actors. Subsequently, I am required to develop a function that randomly designates one actor from the array as the "favorite."
Upon completing this task, I find myself left with an empty array.
Below is the code snippet:
class TVShow {
constructor (title, thematic, principalActors){
var arrayActors = new Array();
this.title=title;
this.thematic=thematic;
principalActors=[];
this.generateFavActor = function(){
var long = principalActors.lenght;
let calc = Math.floor(Math.random()*(long));
arrayActors = principalActors[calc];
}
console.log(arrayActors);
}
}
var show01= new TVShow("The Revolution", "Accion",["Hello","Hello2"]);
show01.generateFavActor();
var show02 = new TVShow("Peaky Blinders", "Drama",["Hello","Hello2", "Hello3"] );
show02.generateFavActor();
var show03 = new TVShow ("Stranger Things", "Accion", ["Hello","Hello2", "Hello3", "Hello4"]);
show03.generateFavActor();
Thank you for your assistance!