当前位置:网站首页>Simple random roll call lottery (written under JS)
Simple random roll call lottery (written under JS)
2022-04-23 07:45:00 【Senior salted fish~】
Take three people at random and don't repeat
<script type="text/javascript">
// choose 3 personal , And not repeated
var names = [" Yan Yu ", " Stop ", " Jiang Cheng ", " Gu Fei ", " Jiang Tian "]
var choice = []
for (var i = 1; i <= 3; i++) {
var index1 = Math.round(Math.random() * (names.length - 1 - 0 + 1) + 0)
if (choice.every(function (item, index) {
return item != names[index1]
}) == true && names[index1] != undefined) {
choice.push(names[index1])
} else {
i = i - 1
}
}
console.log(choice)
</script>
The output shows


The main function codes are also applicable to other language environments
版权声明
本文为[Senior salted fish~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230623087305.html
边栏推荐
- js之DOM学习三种创建元素的方式
- BTree、B+Tree和HASH索引
- 积性函数与迪利克雷卷积
- keytool: command not found
- Solutions to common problems in visualization (VII) solutions to drawing scale setting
- 对STL容器的理解
- 常用的DOS命令
- 判断字符串首尾是否包含目标参数:startsWith()、endsWith()方法
- MySQL index
- Preliminary configuration of OpenGL super Dictionary (freeglut, glew, gltools, GLUT)
猜你喜欢
随机推荐
Super classic & Programming Guide (red and blue book) - Reading Notes
设置了body的最大宽度,但是为什么body的背景颜色还铺满整个页面?
驼峰命名对像
2. Restricted query
Reflection on the systematic design of Android audio and video caching mechanism
Game assisted script development journey
8. Paging query
ABAP CDS VIEW WITH ASSOCIATION示例
3. Sort statement
Visualization Road (IX) detailed explanation of arrow class
SAP PI/PO登录使用及基本功能简介
7.子查询
Django使用mysql数据库报错解决
11.表和库的管理
斐波拉去动态规划
MySQL isolation level
Discussion on arrow function of ES6
学会使用搜索引擎
SAP CR传输请求顺序、依赖检查
反转链表练习









