Javascript document.write不';一旦实际程序完成,就不能显示任何内容 函数中值(列表) { sort(函数(a,b){返回a-b;}); var list_len=list.length; //使用模运算符确定数组的长度是奇数还是偶数。 //使用Math.floor截断数字 //使用Math.round对数字进行四舍五入 如果((列表长度%2)==1) 退货清单[数学楼层(清单2)]; 其他的 返回Math.round((list[list\len/2-1]+list[list\len/2])/2); }//函数结束中位数 //试驾 var my_list_1=[8,3,9,1,4,7]; var my_list_2=[10,-2,0,5,3,1,7]; var med=中值(我的清单1); 文件。填写(“我的清单1的[”中位数为:“,med,”); med=中位数(我的清单2); 文件。填写(“我的清单2的[”中位数为:“,med,”); 写作(“第6.5轮:”,数学第6.5轮);

Javascript document.write不';一旦实际程序完成,就不能显示任何内容 函数中值(列表) { sort(函数(a,b){返回a-b;}); var list_len=list.length; //使用模运算符确定数组的长度是奇数还是偶数。 //使用Math.floor截断数字 //使用Math.round对数字进行四舍五入 如果((列表长度%2)==1) 退货清单[数学楼层(清单2)]; 其他的 返回Math.round((list[list\len/2-1]+list[list\len/2])/2); }//函数结束中位数 //试驾 var my_list_1=[8,3,9,1,4,7]; var my_list_2=[10,-2,0,5,3,1,7]; var med=中值(我的清单1); 文件。填写(“我的清单1的[”中位数为:“,med,”); med=中位数(我的清单2); 文件。填写(“我的清单2的[”中位数为:“,med,”); 写作(“第6.5轮:”,数学第6.5轮);,javascript,internet-explorer,google-chrome,rounding,Javascript,Internet Explorer,Google Chrome,Rounding,我正在使用Visual Studio 2012 ultimate运行此程序。。我得到了所有的结果,但最后没有得到最后一个文档的结果。。另外,当我试图在谷歌浏览器上打开它时,它工作正常。。我上传这些图片是为了告诉你我的意思 document.write在文档第一次加载完毕后调用时会覆盖文档,因此它几乎永远都不是正确的方法。。所有文件都在加载中,请接受最后一份。。我不能上传图片,因为这个关于代码格式的愚蠢错误会弹出 function median(list) { list.sort(fun

我正在使用Visual Studio 2012 ultimate运行此程序。。我得到了所有的结果,但最后没有得到最后一个文档的结果。。另外,当我试图在谷歌浏览器上打开它时,它工作正常。。我上传这些图片是为了告诉你我的意思


document.write在文档第一次加载完毕后调用时会覆盖文档,因此它几乎永远都不是正确的方法。。所有文件都在加载中,请接受最后一份。。我不能上传图片,因为这个关于代码格式的愚蠢错误会弹出
function median(list)
{
list.sort(function (a, b) { return a - b; });
var list_len = list.length;

//Use  the modulus operator to determine whether the array's length is odd or even.
//Use Math.floor to truncate numbers
//Use Math.round to round numbers

if ((list_len % 2) == 1)
    return list[Math.floor(list_len / 2)];
else
    return Math.round((list[list_len / 2 - 1] + list[list_len /  2]) / 2);
} //end of function median

//Test driver
var my_list_1 = [8, 3, 9, 1, 4, 7];
var my_list_2 = [10, -2, 0, 5, 3, 1, 7];

 var med = median(my_list_1);

document.write("Median of [", my_list_1, "] is : ", med, "<br />");
med = median(my_list_2);
document.write("Median of [", my_list_2, "] is : ", med, "<br />");

document.write("Round of 6.5: ", Math.round(6.5));