Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript生成包含随机数的随机数组?_Javascript_Arrays - Fatal编程技术网

Javascript生成包含随机数的随机数组?

Javascript生成包含随机数的随机数组?,javascript,arrays,Javascript,Arrays,我正在为这个类做一个简单的赋值,并尝试使用Javascript创建一个表。我已经把我的桌子摆好了,只是每隔一行显示一个随机数,然后跳到下一行。我怎样才能摆脱随机行 var table = ["Name", "Turn Average", "Surface Area", "100% Boosting"]; var names = ["Octane", "Dominus", "Breakout", "X-Devil", "Batmobile"]; var turnaverages = [2

我正在为这个类做一个简单的赋值,并尝试使用Javascript创建一个表。我已经把我的桌子摆好了,只是每隔一行显示一个随机数,然后跳到下一行。我怎样才能摆脱随机行

 var table = ["Name", "Turn Average", "Surface Area", "100% Boosting"];

 var names = ["Octane", "Dominus", "Breakout", "X-Devil", "Batmobile"];

 var turnaverages = [2.18, 2.22, 2.22, 2.21, 2.25];

 var surfacearea = [34495, 34529, 32679, 34242, 34365];

var maxboost = [1.967, 2.031, 2.035, 2.014, 2.10];

function info() {
document.write("<table>"); 
document.write("<tr>"); 

//these next lines output the table heading (th) tags for the table (this information doesn't repeat in the table)
document.write("<th>Name</th>");
document.write("<th>Turn Average</th>");
document.write("<th>Surface Area</th>");
document.write("<th>100% Boosting</th>");
document.write("</tr>"); //close first table row element
//create a for loop that will last for the number of days in the forecast
for(var i = 0; i < names.length; i++){
    document.write("<tr>"); //create a table row
        //output each table data tag for the table with information pulled 
         from the arrays
        document.write("<td>" + names[i] + "</td>");
        document.write("<td>" + turnaverages[i] + "</td>");
        document.write("<td>" + surfacearea[i] + "</td>");
        document.write("<td>" + maxboost[i] + "</td>");
        document.write("</tr>");
        //depending on the description of the weather for the day, change 
           the image to be representative to that description -- (for 
           example on a rainy day, show the rainy image)
        if ( names[i] === "Dominus" ) {
            document.write("<td>" + turnaverages[i] + surfacearea[i] + 
            maxboost[i] + "</td>");
        }
        else if ( names[i] === "Breakout" ){
            document.write("<td>" + turnaverages[i] + surfacearea[i] + 
             maxboost[i] + "</td>");
        }
            else if ( names[i] === "X-Devil" ){
            document.write("<td>" + turnaverages[i] + surfacearea[i] + 
            maxboost[i] + "</td>");
        }
        else if( names[i] === "Batmobile" ){
            document.write("<td>" + turnaverages[i] + surfacearea[i] + 
            maxboost[i] + "</td>");

        }

       document.write("</tr>"); //close the table row element
     }
      document.write("</table>"); //close the table element
    }
var表=[“名称”、“平均值”、“表面积”、“100%增压”];
变量名称=[“辛烷值”、“多米努斯”、“突破”、“X-魔鬼”、“蝙蝠车”];
var平均值=[2.18,2.22,2.22,2.21,2.25];
var surfacearea=[34495345293267934242 34365];
var maxboost=[1.967,2.031,2.035,2.014,2.10];
函数信息(){
文件。填写(“”);
文件。填写(“”);
//接下来的几行输出表的表标题(th)标记(此信息在表中不重复)
文件。填写(“名称”);
记录。填写(“周转平均值”);
文件。书写(“表面积”);
文件。填写(“100%增压”);
document.write(“”;//关闭第一个表行元素
//创建一个for循环,该循环将持续预测中的天数
对于(var i=0;i
您有

document.write("<td>" + maxboost[i] + "</td>");
document.write("</tr>");
因此,您只需删除第一个
,因为您实际上还不想关闭该行:

var表=[“名称”、“平均值”、“表面积”、“100%增压”];
变量名称=[“辛烷值”、“多米努斯”、“突破”、“X-魔鬼”、“蝙蝠车”];
var平均值=[2.18,2.22,2.22,2.21,2.25];
var surfacearea=[34495345293267934242 34365];
var maxboost=[1.967,2.031,2.035,2.014,2.10];
函数信息(){
文件。填写(“”);
文件。填写(“”);
//接下来的几行输出表的表标题(th)标记(此
文件。填写(“名称”);
记录。填写(“周转平均值”);
文件。书写(“表面积”);
文件。填写(“100%增压”);
document.write(“”;//关闭第一个表行元素
//创建一个for循环,该循环将持续预测中的天数
对于(var i=0;iinfo();
document.error。请使用更现代、更不容易混淆的方法。此函数尝试写入当前文档。如果文档已被处理,则该文档将替换为带有参数的空白文档。您不希望这样做,请改用适当的DOM方法。
document.write("</tr>"); //close the table row element