你好吗?
现在,我正在用 Javascript 学习数组。我已经完成了一个将数组内容显示到 HTML 文件中的函数,但我只收到“未定义”。
首先,我尝试修改“contenido”内部的代码,但我只将“字符”接收到0位置,例如:contenido += "<div id=d"+posicion+">Titulo: " +系列标题[0]。它给我返回了“D”,德克斯特。
我究竟做错了什么?
这是我的代码。
/*Creating a class to structure the information of a TV show by saving the title, theme, array with the main actors and saving the favorite actor in the array.
*/
class SerieTV {
constructor (titulo, tematica, actoresPrincipales){
var arrayActores = new Array();
this.titulo=titulo;
this.tematica=tematica;
this.actores=actoresPrincipales;
/* Adding a function to generate a random favorite actor.
*/
this.generaActorFavorito = function(){
var long = actoresPrincipales.length;
let calc = Math.floor(Math.random()*(long));
arrayActores = actoresPrincipales[calc];
console.log(arrayActores);
}
}
}
/* Creating 3 series, the 1st with 2 actors, 2nd with 3 and 3rd with 4. Later, adding it to a new array called "total_series."
*/
var show01= new SerieTV('Dexter ', 'Drama ', ['Michael C Hall ' ,'Jennifer Carpenter']);
show01.generaActorFavorito();
var show02 = new SerieTV('Samurai Gourmet' , 'Cocina' , ['Naoto Takenaka' ,'Tetsuji Tamayama' , 'Honami Suzuki '] );
show02.generaActorFavorito();
var show03 = new SerieTV ('Breaking Bad ', 'Drama ', ['Aaron Paul ','Bryan Cranston ', 'RJ Mitte ', 'Anna Gunn ']);
show03.generaActorFavorito();
console.log("-------------------------");
var total_series = new Array();
total_series.push(show01);
total_series.push(show02);
total_series.push(show03);
console.log(total_series);
console.log("-------------------------");
幕布斯6054654
慕慕森
相关分类