Skip to content

Instantly share code, notes, and snippets.

@kidapu
Created September 17, 2015 07:50
Show Gist options
  • Save kidapu/7f6fd3e5a3d594a2ca51 to your computer and use it in GitHub Desktop.
Save kidapu/7f6fd3e5a3d594a2ca51 to your computer and use it in GitHub Desktop.
抽選用スクリプト
<!DOCTYPE html>
<html>
<title>アンケート抽選用</title>
<body>
<script type="text/javascript">
var names = [
"Aさん",
"Bさん",
"Cさん",
"Dさん",
"Eさん"];
var max_num = 3;
Array.prototype.shuffle = function()
{
var i = this.length;
while (i)
{
var j = Math.floor(Math.random() * i);
var t = this[--i];
this[i] = this[j];
this[j] = t;
}
return this;
}
names.shuffle();
for (var i=0; i<max_num; i++)
{
var p = document.createElement('p');
p.innerHTML = (i+1) + "位:" + names[i];
document.body.appendChild(p);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment