题解 | #双色球机选一注#

双色球机选一注

http://www.nowcoder.com/practice/4d712994d0364a159f8169b7b0e74d04

function randomFn() {
var activeRed = [];
var num1;
while (activeRed.length < 6) {
num1 = Math.floor(33 * Math.random() + 1);
if (num1 <= 9 && activeRed.indexOf("0" + num1) == -1) {
activeRed.push("0" + num1);
};
if (num1 > 9 && activeRed.indexOf("" + num1) == -1) {
activeRed.push("" + num1);
};
};
activeRed.sort();

var otherRed = [];
for (var i = 1; i <= 33; i++) {
  if (i <= 9 && activeRed.indexOf("0" + i) == -1) {
    otherRed.push("0" + i);
  };
  if (i > 9 && activeRed.indexOf("" + i) == -1) {
    otherRed.push("" + i);
  };
}

var num2 = Math.floor(16 * Math.random() + 1);
activeBlue = num2 > 9 ? "" + num2 : "0" + num2;
var otherBlue = [];
for (var i = 1; i <= 16; i++) {
  if ((i > 9 ? "" + i : "0" + i) != activeBlue) {
    otherBlue.push(i > 9 ? "" + i : "0" + i);
  }
}

var red = document.getElementsByClassName("balls-wp")[0].children;
var blue = document.getElementsByClassName("balls-wp")[1].children;

for (var m = 0; m < 33; m++) {
  if (m < 6) {
    red[m].innerText = activeRed[m];
    red[m].classList.add("active");
  } else {
    red[m].innerText = otherRed[m - 6];
  }
}

for (var n = 0; n < 16; n++) {
  if (n == 0) {
    blue[0].innerText = activeBlue;
    blue[0].classList.add("active");
  } else {
    blue[n].innerText = otherBlue[n - 1];
  }
}
return activeRed.join(",") + "|" + activeBlue;

}

全部评论

相关推荐

不愿透露姓名的神秘牛友
10-29 21:14
疯犬丨哈士奇:喜欢你的人会主动表白,对你有想法的人会很主动,所以要你的公司不会吊着你所以懂了吧
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务