I'm learning Javascript, and I have a problem with arrays in Javascript, and I have to do a class called TV Show with title, thematicand and actors (actors with array) Then, I have to do a function to grab a specific actor and classify it as "favorite" randomly.
Once done, I get an "empty" array.
This is my code.
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();
Thanks!!