var array_nums = new Array (50);
var frequency = 0;
for (i=0; i<array_nums.length; i++){
array_nums [i] = Math.floor ((Math.random() * 50));
for (i=0; i<array_nums.length; i++){
if((i>=10) && (i<=19)){
frequency = frequency+ [i];
alert(frequency);
}
}
}
答案 0 :(得分:0)
var array_nums = [];
var frequency = 0;
for (i=0; i < 50; i++) {
var randInt = Math.floor(Math.random()*50)
array_nums.push(randInt);
if(randInt >= 10 && randInt <= 19) {
frequency = frequency + 1;
}
}
document.getElementById('results').innerHTML = array_nums + '<br/><br/>frequency: ' + frequency;
&#13;
<div id="results"></div>
&#13;
答案 1 :(得分:0)
我们用50个随机数填充一个数组,然后将它减少到一个对象,该对象具有10到19之间每个元素的出现次数,最后一个&#34; all&#34;具有10到19之间所有数字的次数的元素。
<div id="results">
&#13;
{{1}}&#13;