我需要模擬滾動3次模具50次,將每次存儲在數組中,並將結果顯示在表格中。我還需要顯示每個實例添加在一起的結果。對於每個我得到3 + 4 + 2 = 9的第一卷。我有一些代碼,但它不會顯示。我不確定它有什麼問題。Roll 3 die 50 times and each each in a array and display in html
<!--
var array1 = new Array(50);
var array2 = new Array(50);
var array3 = new Array(50);
var array4 = new Array(50);
function roll()
{
var face = Math.floor((Math.random() *6) + 1);
return face;
}
for(var i = 0; i < array.length; i++)
{
array1[i] = roll();
}
for(var i = 0; i < array.length; i++)
{
array2[i] = roll();
}
for(var i = 0; i < array.length; i++)
{
array3[i] = roll();
}
for(var i = 0; i < array.length; i++)
{
array4[i] = array1[i] + array2[i] + array3[i];
}
//Making table
document.write('<table border="1" cellspacing="1" cellpadding="5">')
//Loops through array object and writes values in appropriate table cells
for(var i = 0; i < 50; i++)
{
document.write('<tr>')
document.write('<td>' + i + '</td>');
document.write('<td>' + array1[i] + '</td>');
document.write('<td>' + array2[i] + '</td>');
document.write('<td>' + array3[i] + '</td>');
document.write('<td>' + array4[i] + '</td>');
document.write('</tr>')
}
document.write('</table>')
你的意思是添加此:'文件撰寫(」'+(array1 [i] + array2 [i] + array3 [i] + array4 [i])+'');'在'document.write(''+ array4 [i] +'' );'? – ReGdYN