javascript随机产生3个1一100之间的整数,输出最大和最小数

如题所述

function ran(){
var num =[];
for(var i=0;i<3;i++){
num.push(Math.floor(Math.random() * 100) +1);
}
console.log(num);//已经得到了三个随机整数

var sortnum = num.sort(); //排序,
return {max: sortnum[2], min: sortnum[0], all: sortnum};
}

console.log(ran());

输出结果: max 是最大值; min是最小值; all是三个数字的数组

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-12-10
function randomNum(){

    var max = 0;

    var a= Math.floor(Math.random()*100+1);

    var b=Math.floor(Math.random()*100+1);

    var c=Math.floor(Math.random()*100+1);

    if(a>max) max=a;

    if(b>max) max=b;

    if(c>max) max=c;

    return max;
}

本回答被网友采纳
相似回答