📄 lotto.js
字号:
// create variables
var i, rand, temp, str;
// create a new array of 50 elements
var nums = new Array(50);
// fill elements 1-49 with numbers 1-49
for(i = 1; i < 50; i++) nums[i] = i;
// algorithm to randomize these numbers
for(i = 1; i < 50; i++)
{
rand = Math.ceil(Math.random() * 49 );
temp = nums[i];
nums[i] = nums[rand];
nums[rand] = temp;
}
// add the first six elements to a string
str = "Your six lucky numbers are:\n\n";
for(i = 1; i < 7; i++)
{
str += nums[i];
if(i != 6) str += " - ";
}
// display the string
alert(str);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -