JS代码随机生成20个1到100内的奇数,并存到一个数组中 5
2个回答
展开全部
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
var num = [];
// 随机生成20个1~100的数
for(var i = 0;i<40;i++){
num[i] =parseInt(Math.random()*100);
}
//判断是否能被2整除,删除
for(var i = 0;i<40;i++){
if(num[i]%2 == 0){
delete num[i];
}
}
// 遍历打印
for(var x in num){
document.writeln(num[x]);
}
</script>
</body>
</html>
有点小bug,大概就是这样,我纯手写的
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
var num = [];
// 随机生成20个1~100的数
for(var i = 0;i<40;i++){
num[i] =parseInt(Math.random()*100);
}
//判断是否能被2整除,删除
for(var i = 0;i<40;i++){
if(num[i]%2 == 0){
delete num[i];
}
}
// 遍历打印
for(var x in num){
document.writeln(num[x]);
}
</script>
</body>
</html>
有点小bug,大概就是这样,我纯手写的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询